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