blob: ae1552887b269e781d49e626127a08ffc5c3de03 [file] [log] [blame]
Daniel Dunbara5728872009-12-15 20:14:24 +00001// RUN: %clang_cc1 -fsyntax-only -verify %s
Douglas Gregor9ea62762009-05-21 23:17:49 +00002
3// Test template instantiation for C99-specific features.
4
5// ---------------------------------------------------------------------
6// Designated initializers
7// ---------------------------------------------------------------------
8template<typename T, typename XType, typename YType>
9struct 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
18struct Point2D {
19 float x, y;
20};
21
22template struct DesigInit0<Point2D, int, double>;
23
24struct Point3D {
25 float x, y, z;
26};
27
28template struct DesigInit0<Point3D, int, double>;
29
30struct Color {
31 unsigned char red, green, blue;
32};
33
34struct ColorPoint3D {
35 Color color;
36 float x, y, z;
37};
38
39template struct DesigInit0<ColorPoint3D, int, double>;
40template struct DesigInit0<Color, int, double>; // expected-note{{instantiation}}
41
42template<typename T, int Subscript1, int Subscript2,
43 typename Val1, typename Val2>
44struct 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
55template struct DesigArrayInit0<int[8], 5, 3, float, int>;
56template struct DesigArrayInit0<int[8], 5, 13, float, int>; // expected-note{{instantiation}}
Douglas Gregorc4bb7bf2009-05-21 23:30:39 +000057
58template<typename T, int Subscript1, int Subscript2,
59 typename Val1>
60struct DesigArrayRangeInit0 {
61 void f(Val1 val1) {
62 T array = {
63 [Subscript1...Subscript2] = val1 // expected-error{{exceeds}}
64 };
65 }
66};
67
68template struct DesigArrayRangeInit0<int[8], 3, 5, float>;
69template struct DesigArrayRangeInit0<int[8], 5, 13, float>; // expected-note{{instantiation}}
Douglas Gregor690dc7f2009-05-21 23:48:18 +000070
71// ---------------------------------------------------------------------
72// Compound literals
73// ---------------------------------------------------------------------
74template<typename T, typename Arg1, typename Arg2>
75struct CompoundLiteral0 {
76 T f(Arg1 a1, Arg2 a2) {
77 return (T){a1, a2};
78 }
79};
80
81template struct CompoundLiteral0<Point2D, int, float>;