Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / SemaTemplate / instantiate-c99.cpp
blobb0183ff76220f91b43f1225880021a431a174f7e
1 // RUN: %clang_cc1 -Wno-c99-extensions -Wno-reorder -fsyntax-only -verify %s
2 // RUN: %clang_cc1 -Wno-c99-extensions -Wno-reorder -fsyntax-only -verify -std=c++98 %s
3 // RUN: %clang_cc1 -Wno-c99-extensions -Wno-reorder -fsyntax-only -verify -std=c++11 %s
5 // Test template instantiation for C99-specific features.
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
25 struct Point2D {
26 float x, y;
29 template struct DesigInit0<Point2D, int, double>;
31 struct Point3D {
32 float x, y, z;
35 template struct DesigInit0<Point3D, int, double>;
37 struct Color {
38 unsigned char red, green, blue;
41 struct ColorPoint3D {
42 Color color;
43 float x, y, z;
46 template struct DesigInit0<ColorPoint3D, int, double>;
47 template struct DesigInit0<Color, int, double>; // expected-note{{instantiation}}
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}}
62 int array2[10] = { [5] = 3 };
66 template struct DesigArrayInit0<int[8], 5, 3, float, int>;
67 template struct DesigArrayInit0<int[8], 5, 13, float, int>; // expected-note{{instantiation}}
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
83 template struct DesigArrayRangeInit0<int[8], 3, 5, float>;
84 template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}}
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
100 template struct CompoundLiteral0<Point2D, int, float>;