Debian Codegraph @

clang/test/Parser/cxx-ambig-init-templ.cpp

raw
1 // RUN: %clang_cc1 -Wno-uninitialized -std=c++11 -verify %s
2
3 template<int> struct c { c(int) = delete; typedef void val; operator int() const; };
4
5 int f;
6 int val;
7 int foobar;
8 struct S {
9 int k1 = a < b < c, d > ::val, e1;
10 int k2 = a < b, c < d > ::val, e2;
11 int k3 = b < a < c, d > ::val, e3;
12 int k4 = b < c, x, y = d > ::val, e4;
13 int k5 = T1 < b, &S::operator=(int); // expected-error {{extra qualification}}
14 int k6 = T2 < b, &S::operator= >::val;
15 int k7 = T1 < b, &S::operator>(int); // expected-error {{extra qualification}}
16 int k8 = T2 < b, &S::operator> >::val;
17 int k9 = T3 < a < b, c >> (d), e5 = 1 > (e4);
18 int k10 = 0 < T3 < a < b, c >> (d
19 ) // expected-error {{expected ';' at end of declaration}}
20 , a > (e4);
21 int k11 = 0 < 1, c<3>::*ptr;
22 int k12 = e < 0, int a<b<c>::* >(), e11;
23
24 void f1(
25 int k1 = a < b < c, d > ::val,
26 int k2 = b < a < c, d > ::val,
27 int k3 = b < c, int x = 0 > ::val,
28 int k4 = a < b, T3 < int > >(), // expected-error {{must be an expression}}
29 int k5 = a < b, c < d > ::val,
30 int k6 = a < b, c < d > (n) // expected-error {{undeclared identifier 'n'}}
31 );
32
33 static void f1b(
34 int k6 = a < b, c < d > (f)
35 );
36 using f1b_T = decltype(f1b(0)); // only one parameter, because second param
37 // would be missing its default argument
38
39 void f2a(
40 // T3<int> here is a parameter type, so must be declared before it is used.
41 int k1 = c < b, T3 < int > x = 0 // expected-error {{no template named 'T3'}}
42 );
43
44 template<typename, int=0> struct T3 { T3(int); operator int(); };
45
46 void f2b(
47 int k1 = c < b, T3 < int > x = 0 // ok
48 );
49
50 // This is a one-parameter function. Ensure we don't typo-correct it to
51 // int = a < b, c < foobar > ()
52 // ... which would be a function with two parameters.
53 int f3(int = a < b, c < goobar > ());
54 static constexpr int (S::*f3_test)(int) = &S::f3;
55
56 void f4(
57 int k1 = a<1,2>::val,
58 int missing_default // expected-error {{missing default argument on parameter}}
59 );
60
61 void f5(
62 int k1 = b < c,
63 int missing_default // expected-error {{missing default argument on parameter}}
64 );
65
66 // FIXME: We should ideally disambiguate this as two parameters.
67 void f6(
68 int k = b < c, // expected-error {{unexpected end of default argument}}
69 unsigned int (missing_default)
70 );
71
72 template<int, int = 0> struct a { // expected-note {{here}}
73 a();
74 a(int);
75 static const int val = 0;
76 operator int();
77 };
78 static const int b = 0, c = 1, d = 2, goobar = 3;
79 template<int, typename> struct e { operator int(); };
80 static const int f = 0;
81
82 int mp1 = 0 < 1,
83 a<b<c,b<c>::*mp2,
84 mp3 = 0 > a<b<c>::val,
85 a<b<c,b<c>::*mp4 = 0,
86 a<b<c,b<c>::*mp5 {0},
87 a<b<c,b<c>::*mp6;
88
89 int np1 = e<0, int a<b<c,b<c>::*>();
90
91 static const int T1 = 4;
92 template<int, int &(S::*)(int)> struct T2 { static const int val = 0; };
93 };
94
95 namespace NoAnnotationTokens {
96 template<bool> struct Bool { Bool(int); };
97 static const bool in_class = false;
98
99 struct Test {
100 // Check we don't keep around a Bool<false> annotation token here.
101 int f(Bool<true> = X<Y, Bool<in_class> >(0));
102
103 // But it's OK if we do here.
104 int g(Bool<true> = Z<Y, Bool<in_class> = Bool<false>(0));
105
106 static const bool in_class = true;
107 template<int, typename U> using X = U;
108 static const int Y = 0, Z = 0;
109 };
110 }
111
112 namespace ImplicitInstantiation {
113 template<typename T> struct HasError { typename T::error error; }; // expected-error {{has no members}}
114
115 struct S {
116 // This triggers the instantiation of the outer HasError<int> during
117 // disambiguation, even though it uses the inner HasError<int>.
118 void f(int a = X<Y, HasError<int>::Z >()); // expected-note {{in instantiation of}}
119
120 template<typename, typename> struct X { operator int(); };
121 typedef int Y;
122 template<typename> struct HasError { typedef int Z; };
123 };
124
125 HasError<int> hei;
126 }
127
128 namespace CWG325 {
129 template <int A, typename B> struct T { static int i; operator int(); };
130 class C {
131 int Foo (int i = T<1, int>::i);
132 };
133
134 class D {
135 int Foo (int i = T<1, int>::i);
136 template <int A, typename B> struct T {static int i;};
137 };
138
139 const int a = 0;
140 typedef int b;
141 T<a,b> c;
142 struct E {
143 int n = T<a,b>(c);
144 };
145 }
146
147 namespace Operators {
148 struct Y {};
149 constexpr int operator,(const Y&, const Y&) { return 8; }
150 constexpr int operator>(const Y&, const Y&) { return 8; }
151 constexpr int operator<(const Y&, const Y&) { return 8; }
152 constexpr int operator>>(const Y&, const Y&) { return 8; }
153
154 struct X {
155 typedef int (*Fn)(const Y&, const Y&);
156
157 Fn a = operator,, b = operator<, c = operator>;
158 void f(Fn a = operator,, Fn b = operator<, Fn c = operator>);
159
160 int k1 = T1<0, operator<, operator>, operator<>::val, l1;
161 int k2 = T1<0, operator>, operator,, operator,>::val, l2;
162 int k3 = T2<0, operator,(Y{}, Y{}), operator<(Y{}, Y{})>::val, l3;
163 int k4 = T2<0, operator>(Y{}, Y{}), operator,(Y{}, Y{})>::val, l4;
164 int k5 = T3<0, operator>>>::val, l5;
165 int k6 = T4<0, T3<0, operator>>>>::val, l6;
166
167 template<int, Fn, Fn, Fn> struct T1 { enum { val }; };
168 template<int, int, int> struct T2 { enum { val }; };
169 template<int, Fn> struct T3 { enum { val }; };
170 template<int, typename T> struct T4 : T {};
171 };
172 }
173
174 namespace ElaboratedTypeSpecifiers {
175 struct S {
176 int f(int x = T<a, struct S>());
177 int h(int x = T<a, union __attribute__(()) U>());
178 int i(int x = T<a, enum E>());
179 int j(int x = T<a, struct S::template T<0, enum E>>());
180 template <int, typename> struct T { operator int(); };
181 static const int a = 0;
182 enum E {};
183 };
184 }
185
186 namespace PR20459 {
187 template <typename EncTraits> struct A {
188 void foo(int = EncTraits::template TypeEnc<int, int>::val); // ok
189 };
190 }