Home | History | Annotate | Download | only in SemaTemplate
      1 // RUN: %clang_cc1 -fsyntax-only -verify %s
      2 
      3 // Test template instantiation for C99-specific features.
      4 
      5 // ---------------------------------------------------------------------
      6 // Designated initializers
      7 // ---------------------------------------------------------------------
      8 template<typename T, typename XType, typename YType>
      9 struct DesigInit0 {
     10   void f(XType x, YType y) {
     11     T agg = {
     12       .y = y, // expected-error{{does not refer}}
     13       .x = x  // expected-error{{does not refer}}
     14     };
     15   }
     16 };
     17 
     18 struct Point2D {
     19   float x, y;
     20 };
     21 
     22 template struct DesigInit0<Point2D, int, double>;
     23 
     24 struct Point3D {
     25   float x, y, z;
     26 };
     27 
     28 template struct DesigInit0<Point3D, int, double>;
     29 
     30 struct Color {
     31   unsigned char red, green, blue;
     32 };
     33 
     34 struct ColorPoint3D {
     35   Color color;
     36   float x, y, z;
     37 };
     38 
     39 template struct DesigInit0<ColorPoint3D, int, double>;
     40 template struct DesigInit0<Color, int, double>; // expected-note{{instantiation}}
     41 
     42 template<typename T, int Subscript1, int Subscript2,
     43          typename Val1, typename Val2>
     44 struct DesigArrayInit0 {
     45   void f(Val1 val1, Val2 val2) {
     46     T array = {
     47       [Subscript1] = val1,
     48       [Subscript2] = val2 // expected-error{{exceeds array bounds}}
     49     };
     50 
     51     int array2[10] = { [5] = 3 };
     52   }
     53 };
     54 
     55 template struct DesigArrayInit0<int[8], 5, 3, float, int>;
     56 template struct DesigArrayInit0<int[8], 5, 13, float, int>; // expected-note{{instantiation}}
     57 
     58 template<typename T, int Subscript1, int Subscript2,
     59          typename Val1>
     60 struct DesigArrayRangeInit0 {
     61   void f(Val1 val1) {
     62     T array = {
     63       [Subscript1...Subscript2] = val1 // expected-error{{exceeds}}
     64     };
     65   }
     66 };
     67 
     68 template struct DesigArrayRangeInit0<int[8], 3, 5, float>;
     69 template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}}
     70 
     71 // ---------------------------------------------------------------------
     72 // Compound literals
     73 // ---------------------------------------------------------------------
     74 template<typename T, typename Arg1, typename Arg2>
     75 struct CompoundLiteral0 {
     76   T f(Arg1 a1, Arg2 a2) {
     77     return (T){a1, a2};
     78   }
     79 };
     80 
     81 template struct CompoundLiteral0<Point2D, int, float>;
     82