xref: /aosp_15_r20/external/clang/test/CXX/drs/dr3xx.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2*67e74705SXin Li // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3*67e74705SXin Li // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4*67e74705SXin Li // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5*67e74705SXin Li 
6*67e74705SXin Li namespace dr300 { // dr300: yes
f(R (&)(A))7*67e74705SXin Li   template<typename R, typename A> void f(R (&)(A)) {}
8*67e74705SXin Li   int g(int);
h()9*67e74705SXin Li   void h() { f(g); }
10*67e74705SXin Li }
11*67e74705SXin Li 
12*67e74705SXin Li namespace dr301 { // dr301: yes
13*67e74705SXin Li   // see also dr38
14*67e74705SXin Li   struct S;
15*67e74705SXin Li   template<typename T> void operator+(T, T);
16*67e74705SXin Li   void operator-(S, S);
17*67e74705SXin Li 
f()18*67e74705SXin Li   void f() {
19*67e74705SXin Li     bool a = (void(*)(S, S))operator+<S> <
20*67e74705SXin Li              (void(*)(S, S))operator+<S>;
21*67e74705SXin Li     bool b = (void(*)(S, S))operator- <
22*67e74705SXin Li              (void(*)(S, S))operator-;
23*67e74705SXin Li     bool c = (void(*)(S, S))operator+ <
24*67e74705SXin Li              (void(*)(S, S))operator-; // expected-error {{expected '>'}}
25*67e74705SXin Li   }
26*67e74705SXin Li 
f()27*67e74705SXin Li   template<typename T> void f() {
28*67e74705SXin Li     typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
29*67e74705SXin Li     // FIXME: This shouldn't say (null).
30*67e74705SXin Li     class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
31*67e74705SXin Li     enum T::template operator+<int> c; // expected-error {{expected identifier}} expected-error {{does not declare anything}}
32*67e74705SXin Li     enum T::template operator+<int>::E d; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}}
33*67e74705SXin Li     enum T::template X<int>::E e;
34*67e74705SXin Li     T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
35*67e74705SXin Li     T::template operator+<int>(0); // ok
36*67e74705SXin Li   }
37*67e74705SXin Li 
38*67e74705SXin Li   template<typename T> class operator&<T*> {}; // expected-error +{{}}
39*67e74705SXin Li   template<typename T> class T::operator& {}; // expected-error +{{}}
40*67e74705SXin Li   template<typename T> class S::operator&<T*> {}; // expected-error +{{}}
41*67e74705SXin Li }
42*67e74705SXin Li 
43*67e74705SXin Li namespace dr302 { // dr302: yes
44*67e74705SXin Li   struct A { A(); ~A(); };
45*67e74705SXin Li #if __cplusplus < 201103L
46*67e74705SXin Li   struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
47*67e74705SXin Li     const int n; // expected-note {{declared here}}
48*67e74705SXin Li     A a;
49*67e74705SXin Li   } b = B(); // expected-note {{first required here}}
50*67e74705SXin Li   // Trivial default constructor C::C() is not called here.
51*67e74705SXin Li   struct C {
52*67e74705SXin Li     const int n;
53*67e74705SXin Li   } c = C();
54*67e74705SXin Li #else
55*67e74705SXin Li   struct B {
56*67e74705SXin Li     const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
57*67e74705SXin Li     A a;
58*67e74705SXin Li   } b = B(); // expected-error {{call to implicitly-deleted default constructor}}
59*67e74705SXin Li   // C::C() is called here, because even though it's trivial, it's deleted.
60*67e74705SXin Li   struct C {
61*67e74705SXin Li     const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
62*67e74705SXin Li   } c = C(); // expected-error {{call to implicitly-deleted default constructor}}
63*67e74705SXin Li   struct D {
64*67e74705SXin Li     const int n = 0;
65*67e74705SXin Li   } d = D();
66*67e74705SXin Li #endif
67*67e74705SXin Li }
68*67e74705SXin Li 
69*67e74705SXin Li // dr303: na
70*67e74705SXin Li 
71*67e74705SXin Li namespace dr304 { // dr304: yes
72*67e74705SXin Li   typedef int &a;
73*67e74705SXin Li   int n = a(); // expected-error {{requires an initializer}}
74*67e74705SXin Li 
75*67e74705SXin Li   struct S { int &b; };
76*67e74705SXin Li   int m = S().b;
77*67e74705SXin Li #if __cplusplus < 201103L
78*67e74705SXin Li   // expected-error@-3 {{requires an initializer}}
79*67e74705SXin Li   // expected-note@-3 {{in value-initialization}}
80*67e74705SXin Li #else
81*67e74705SXin Li   // expected-error@-5 {{deleted}}
82*67e74705SXin Li   // expected-note@-7 {{reference}}
83*67e74705SXin Li #endif
84*67e74705SXin Li }
85*67e74705SXin Li 
86*67e74705SXin Li namespace dr305 { // dr305: no
87*67e74705SXin Li   struct A {
88*67e74705SXin Li     typedef A C;
89*67e74705SXin Li   };
f(A * a)90*67e74705SXin Li   void f(A *a) {
91*67e74705SXin Li     struct A {};
92*67e74705SXin Li     a->~A();
93*67e74705SXin Li     a->~C();
94*67e74705SXin Li   }
95*67e74705SXin Li   typedef A B;
g(B * b)96*67e74705SXin Li   void g(B *b) {
97*67e74705SXin Li     b->~B();
98*67e74705SXin Li     b->~C();
99*67e74705SXin Li   }
h(B * b)100*67e74705SXin Li   void h(B *b) {
101*67e74705SXin Li     struct B {}; // expected-note {{declared here}}
102*67e74705SXin Li     b->~B(); // expected-error {{does not match}}
103*67e74705SXin Li   }
104*67e74705SXin Li 
105*67e74705SXin Li   template<typename T> struct X {};
i(X<int> * x)106*67e74705SXin Li   void i(X<int>* x) {
107*67e74705SXin Li     struct X {};
108*67e74705SXin Li     x->~X<int>();
109*67e74705SXin Li     x->~X();
110*67e74705SXin Li     x->~X<char>(); // expected-error {{no member named}}
111*67e74705SXin Li   }
112*67e74705SXin Li 
113*67e74705SXin Li #if __cplusplus >= 201103L
114*67e74705SXin Li   struct Y {
115*67e74705SXin Li     template<typename T> using T1 = Y;
116*67e74705SXin Li   };
117*67e74705SXin Li   template<typename T> using T2 = Y;
j(Y * y)118*67e74705SXin Li   void j(Y *y) {
119*67e74705SXin Li     y->~T1<int>();
120*67e74705SXin Li     y->~T2<int>();
121*67e74705SXin Li   }
122*67e74705SXin Li   struct Z {
123*67e74705SXin Li     template<typename T> using T2 = T;
124*67e74705SXin Li   };
k(Z * z)125*67e74705SXin Li   void k(Z *z) {
126*67e74705SXin Li     // FIXME: This diagnostic is terrible.
127*67e74705SXin Li     z->~T1<int>(); // expected-error {{'T1' following the 'template' keyword does not refer to a template}} expected-error +{{}}
128*67e74705SXin Li     z->~T2<int>(); // expected-error {{no member named '~int'}}
129*67e74705SXin Li     z->~T2<Z>();
130*67e74705SXin Li   }
131*67e74705SXin Li 
132*67e74705SXin Li   // FIXME: This is valid.
133*67e74705SXin Li   namespace Q {
134*67e74705SXin Li     template<typename A> struct R {};
135*67e74705SXin Li   }
136*67e74705SXin Li   template<typename A> using R = Q::R<int>;
qr(Q::R<int> x)137*67e74705SXin Li   void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}}
138*67e74705SXin Li #endif
139*67e74705SXin Li }
140*67e74705SXin Li 
141*67e74705SXin Li namespace dr306 { // dr306: no
142*67e74705SXin Li   // FIXME: dup 39
143*67e74705SXin Li   // FIXME: This should be accepted.
144*67e74705SXin Li   struct A { struct B {}; }; // expected-note 2{{member}}
145*67e74705SXin Li   struct C { typedef A::B B; }; // expected-note {{member}}
146*67e74705SXin Li   struct D : A, A::B, C {};
147*67e74705SXin Li   D::B b; // expected-error {{found in multiple base classes of different types}}
148*67e74705SXin Li }
149*67e74705SXin Li 
150*67e74705SXin Li // dr307: na
151*67e74705SXin Li 
152*67e74705SXin Li namespace dr308 { // dr308: yes
153*67e74705SXin Li   // This is mostly an ABI library issue.
154*67e74705SXin Li   struct A {};
155*67e74705SXin Li   struct B : A {};
156*67e74705SXin Li   struct C : A {};
157*67e74705SXin Li   struct D : B, C {};
f()158*67e74705SXin Li   void f() {
159*67e74705SXin Li     try {
160*67e74705SXin Li       throw D();
161*67e74705SXin Li     } catch (const A&) { // expected-note {{for type 'const dr308::A &'}}
162*67e74705SXin Li       // unreachable
163*67e74705SXin Li     } catch (const B&) { // expected-warning {{exception of type 'const dr308::B &' will be caught by earlier handler}}
164*67e74705SXin Li       // get here instead
165*67e74705SXin Li     }
166*67e74705SXin Li   }
167*67e74705SXin Li }
168*67e74705SXin Li 
169*67e74705SXin Li // dr309: dup 485
170*67e74705SXin Li 
171*67e74705SXin Li namespace dr311 { // dr311: yes
172*67e74705SXin Li   namespace X { namespace Y {} }
173*67e74705SXin Li   namespace X::Y {}
174*67e74705SXin Li #if __cplusplus <= 201402L
175*67e74705SXin Li   // expected-error@-2 {{define each namespace separately}}
176*67e74705SXin Li #endif
177*67e74705SXin Li   namespace X {
178*67e74705SXin Li     namespace X::Y {}
179*67e74705SXin Li #if __cplusplus <= 201402L
180*67e74705SXin Li   // expected-error@-2 {{define each namespace separately}}
181*67e74705SXin Li #endif
182*67e74705SXin Li   }
183*67e74705SXin Li   // FIXME: The diagnostics here are not very good.
184*67e74705SXin Li   namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}}
185*67e74705SXin Li }
186*67e74705SXin Li 
187*67e74705SXin Li // dr312: dup 616
188*67e74705SXin Li 
189*67e74705SXin Li namespace dr313 { // dr313: dup 299 c++11
190*67e74705SXin Li   struct A { operator int() const; };
191*67e74705SXin Li   int *p = new int[A()];
192*67e74705SXin Li #if __cplusplus < 201103L
193*67e74705SXin Li   // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
194*67e74705SXin Li #endif
195*67e74705SXin Li }
196*67e74705SXin Li 
197*67e74705SXin Li namespace dr314 { // FIXME 314: dup 1710
198*67e74705SXin Li   template<typename T> struct A {
199*67e74705SXin Li     template<typename U> struct B {};
200*67e74705SXin Li   };
201*67e74705SXin Li   template<typename T> struct C : public A<T>::template B<T> {
202*67e74705SXin Li     C() : A<T>::template B<T>() {}
203*67e74705SXin Li   };
204*67e74705SXin Li }
205*67e74705SXin Li 
206*67e74705SXin Li // dr315: na
207*67e74705SXin Li // dr316: sup 1004
208*67e74705SXin Li 
209*67e74705SXin Li namespace dr317 { // dr317: 3.5
210*67e74705SXin Li   void f() {} // expected-note {{previous}}
211*67e74705SXin Li   inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
212*67e74705SXin Li 
213*67e74705SXin Li   int g();
214*67e74705SXin Li   int n = g();
215*67e74705SXin Li   inline int g() { return 0; }
216*67e74705SXin Li 
217*67e74705SXin Li   int h();
218*67e74705SXin Li   int m = h();
219*67e74705SXin Li   int h() { return 0; } // expected-note {{previous}}
220*67e74705SXin Li   inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
221*67e74705SXin Li }
222*67e74705SXin Li 
223*67e74705SXin Li namespace dr318 { // dr318: sup 1310
224*67e74705SXin Li   struct A {};
225*67e74705SXin Li   struct A::A a;
226*67e74705SXin Li }
227*67e74705SXin Li 
228*67e74705SXin Li namespace dr319 { // dr319: no
229*67e74705SXin Li   // FIXME: dup dr389
230*67e74705SXin Li   // FIXME: We don't have a diagnostic for a name with linkage
231*67e74705SXin Li   //        having a type without linkage.
232*67e74705SXin Li   typedef struct {
233*67e74705SXin Li     int i;
234*67e74705SXin Li   } *ps;
235*67e74705SXin Li   extern "C" void f(ps);
236*67e74705SXin Li   void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
237*67e74705SXin Li 
238*67e74705SXin Li   static enum { e } a1;
239*67e74705SXin Li   enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
240*67e74705SXin Li 
241*67e74705SXin Li   enum { n1 = 1u };
242*67e74705SXin Li   typedef int (*pa)[n1];
243*67e74705SXin Li   pa parr; // ok, type has linkage despite using 'n1'
244*67e74705SXin Li 
245*67e74705SXin Li   template<typename> struct X {};
246*67e74705SXin Li 
247*67e74705SXin Li   void f() {
248*67e74705SXin Li     struct A { int n; };
249*67e74705SXin Li     extern A a; // FIXME: ill-formed
250*67e74705SXin Li     X<A> xa;
251*67e74705SXin Li 
252*67e74705SXin Li     typedef A B;
253*67e74705SXin Li     extern B b; // FIXME: ill-formed
254*67e74705SXin Li     X<B> xb;
255*67e74705SXin Li 
256*67e74705SXin Li     const int n = 1;
257*67e74705SXin Li     typedef int (*C)[n];
258*67e74705SXin Li     extern C c; // ok
259*67e74705SXin Li     X<C> xc;
260*67e74705SXin Li   }
261*67e74705SXin Li #if __cplusplus < 201103L
262*67e74705SXin Li   // expected-error@-12 {{uses local type 'A'}}
263*67e74705SXin Li   // expected-error@-9 {{uses local type 'A'}}
264*67e74705SXin Li #endif
265*67e74705SXin Li }
266*67e74705SXin Li 
267*67e74705SXin Li namespace dr320 { // dr320: yes
268*67e74705SXin Li #if __cplusplus >= 201103L
269*67e74705SXin Li   struct X {
270*67e74705SXin Li     constexpr X() {}
271*67e74705SXin Li     constexpr X(const X &x) : copies(x.copies + 1) {}
272*67e74705SXin Li     unsigned copies = 0;
273*67e74705SXin Li   };
274*67e74705SXin Li   constexpr X f(X x) { return x; }
275*67e74705SXin Li   constexpr unsigned g(X x) { return x.copies; }
276*67e74705SXin Li   static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
277*67e74705SXin Li #endif
278*67e74705SXin Li }
279*67e74705SXin Li 
280*67e74705SXin Li namespace dr321 { // dr321: dup 557
281*67e74705SXin Li   namespace N {
282*67e74705SXin Li     template<int> struct A {
283*67e74705SXin Li       template<int> struct B;
284*67e74705SXin Li     };
285*67e74705SXin Li     template<> template<> struct A<0>::B<0>;
286*67e74705SXin Li     void f(A<0>::B<0>);
287*67e74705SXin Li   }
288*67e74705SXin Li   template<> template<> struct N::A<0>::B<0> {};
289*67e74705SXin Li 
290*67e74705SXin Li   template<typename T> void g(T t) { f(t); }
291*67e74705SXin Li   template void g(N::A<0>::B<0>);
292*67e74705SXin Li 
293*67e74705SXin Li   namespace N {
294*67e74705SXin Li     template<typename> struct I { friend bool operator==(const I&, const I&); };
295*67e74705SXin Li   }
296*67e74705SXin Li   N::I<int> i, j;
297*67e74705SXin Li   bool x = i == j;
298*67e74705SXin Li }
299*67e74705SXin Li 
300*67e74705SXin Li namespace dr322 { // dr322: yes
301*67e74705SXin Li   struct A {
302*67e74705SXin Li     template<typename T> operator T&();
303*67e74705SXin Li   } a;
304*67e74705SXin Li   int &r = static_cast<int&>(a);
305*67e74705SXin Li   int &s = a;
306*67e74705SXin Li }
307*67e74705SXin Li 
308*67e74705SXin Li // dr323: no
309*67e74705SXin Li 
310*67e74705SXin Li namespace dr324 { // dr324: yes
311*67e74705SXin Li   struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}}
312*67e74705SXin Li   int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}}
313*67e74705SXin Li   int *b = &s.n; // expected-error {{address of bit-field}}
314*67e74705SXin Li   int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}}
315*67e74705SXin Li   int *d = &(s.n = 0); // expected-error {{address of bit-field}}
316*67e74705SXin Li   int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}}
317*67e74705SXin Li   int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}}
318*67e74705SXin Li   int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}}
319*67e74705SXin Li   int *h = &(void(), s.n); // expected-error {{address of bit-field}}
320*67e74705SXin Li   int *i = &++s.n; // expected-error {{address of bit-field}}
321*67e74705SXin Li }
322*67e74705SXin Li 
323*67e74705SXin Li namespace dr326 { // dr326: yes
324*67e74705SXin Li   struct S {};
325*67e74705SXin Li   int test[__is_trivially_constructible(S, const S&) ? 1 : -1];
326*67e74705SXin Li }
327*67e74705SXin Li 
328*67e74705SXin Li namespace dr327 { // dr327: dup 538
329*67e74705SXin Li   struct A;
330*67e74705SXin Li   class A {};
331*67e74705SXin Li 
332*67e74705SXin Li   class B;
333*67e74705SXin Li   struct B {};
334*67e74705SXin Li }
335*67e74705SXin Li 
336*67e74705SXin Li namespace dr328 { // dr328: yes
337*67e74705SXin Li   struct A; // expected-note 3{{forward declaration}}
338*67e74705SXin Li   struct B { A a; }; // expected-error {{incomplete}}
339*67e74705SXin Li   template<typename> struct C { A a; }; // expected-error {{incomplete}}
340*67e74705SXin Li   A *p = new A[0]; // expected-error {{incomplete}}
341*67e74705SXin Li }
342*67e74705SXin Li 
343*67e74705SXin Li namespace dr329 { // dr329: 3.5
344*67e74705SXin Li   struct B {};
345*67e74705SXin Li   template<typename T> struct A : B {
346*67e74705SXin Li     friend void f(A a) { g(a); }
347*67e74705SXin Li     friend void h(A a) { g(a); } // expected-error {{undeclared}}
348*67e74705SXin Li     friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}}
349*67e74705SXin Li   };
350*67e74705SXin Li   A<int> a;
351*67e74705SXin Li   A<char> b; // expected-note {{instantiation}}
352*67e74705SXin Li 
353*67e74705SXin Li   void test() {
354*67e74705SXin Li     h(a); // expected-note {{instantiation}}
355*67e74705SXin Li   }
356*67e74705SXin Li }
357*67e74705SXin Li 
358*67e74705SXin Li namespace dr331 { // dr331: yes
359*67e74705SXin Li   struct A {
360*67e74705SXin Li     A(volatile A&); // expected-note {{candidate}}
361*67e74705SXin Li   } const a, b(a); // expected-error {{no matching constructor}}
362*67e74705SXin Li }
363*67e74705SXin Li 
364*67e74705SXin Li namespace dr332 { // dr332: dup 577
365*67e74705SXin Li   void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
366*67e74705SXin Li   void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
367*67e74705SXin Li   void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}}
368*67e74705SXin Li }
369*67e74705SXin Li 
370*67e74705SXin Li namespace dr333 { // dr333: yes
371*67e74705SXin Li   int n = 0;
372*67e74705SXin Li   int f(int(n));
373*67e74705SXin Li   int g((int(n)));
374*67e74705SXin Li   int h = f(g);
375*67e74705SXin Li }
376*67e74705SXin Li 
377*67e74705SXin Li namespace dr334 { // dr334: yes
378*67e74705SXin Li   template<typename T> void f() {
379*67e74705SXin Li     T x;
380*67e74705SXin Li     f((x, 123));
381*67e74705SXin Li   }
382*67e74705SXin Li   struct S {
383*67e74705SXin Li     friend S operator,(S, int);
384*67e74705SXin Li     friend void f(S);
385*67e74705SXin Li   };
386*67e74705SXin Li   template void f<S>();
387*67e74705SXin Li }
388*67e74705SXin Li 
389*67e74705SXin Li // dr335: no
390*67e74705SXin Li 
391*67e74705SXin Li namespace dr336 { // dr336: yes
392*67e74705SXin Li   namespace Pre {
393*67e74705SXin Li     template<class T1> class A {
394*67e74705SXin Li       template<class T2> class B {
395*67e74705SXin Li         template<class T3> void mf1(T3);
396*67e74705SXin Li         void mf2();
397*67e74705SXin Li       };
398*67e74705SXin Li     };
399*67e74705SXin Li     template<> template<class X> class A<int>::B {};
400*67e74705SXin Li     template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}}
401*67e74705SXin Li     template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
402*67e74705SXin Li   }
403*67e74705SXin Li   namespace Post {
404*67e74705SXin Li     template<class T1> class A {
405*67e74705SXin Li       template<class T2> class B {
406*67e74705SXin Li         template<class T3> void mf1(T3);
407*67e74705SXin Li         void mf2();
408*67e74705SXin Li       };
409*67e74705SXin Li     };
410*67e74705SXin Li     template<> template<class X> class A<int>::B {
411*67e74705SXin Li       template<class T> void mf1(T);
412*67e74705SXin Li     };
413*67e74705SXin Li     template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
414*67e74705SXin Li     // FIXME: This diagnostic isn't very good.
415*67e74705SXin Li     template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
416*67e74705SXin Li   }
417*67e74705SXin Li }
418*67e74705SXin Li 
419*67e74705SXin Li namespace dr337 { // dr337: yes
420*67e74705SXin Li   template<typename T> void f(T (*)[1]);
421*67e74705SXin Li   template<typename T> int &f(...);
422*67e74705SXin Li 
423*67e74705SXin Li   struct A { virtual ~A() = 0; };
424*67e74705SXin Li   int &r = f<A>(0);
425*67e74705SXin Li 
426*67e74705SXin Li   // FIXME: The language rules here are completely broken. We cannot determine
427*67e74705SXin Li   // whether an incomplete type is abstract. See DR1640, which will probably
428*67e74705SXin Li   // supersede this one and remove this rule.
429*67e74705SXin Li   struct B;
430*67e74705SXin Li   int &s = f<B>(0); // expected-error {{of type 'void'}}
431*67e74705SXin Li   struct B { virtual ~B() = 0; };
432*67e74705SXin Li }
433*67e74705SXin Li 
434*67e74705SXin Li namespace dr339 { // dr339: yes
435*67e74705SXin Li   template <int I> struct A { static const int value = I; };
436*67e74705SXin Li 
437*67e74705SXin Li   char xxx(int);
438*67e74705SXin Li   char (&xxx(float))[2];
439*67e74705SXin Li 
440*67e74705SXin Li   template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}}
441*67e74705SXin Li 
442*67e74705SXin Li   void test() {
443*67e74705SXin Li     A<1> a = f(0);
444*67e74705SXin Li     A<2> b = f(0.0f);
445*67e74705SXin Li     A<3> c = f("foo"); // expected-error {{no matching function}}
446*67e74705SXin Li   }
447*67e74705SXin Li 
448*67e74705SXin Li 
449*67e74705SXin Li   char f(int);
450*67e74705SXin Li   int f(...);
451*67e74705SXin Li 
452*67e74705SXin Li   template <class T> struct conv_int {
453*67e74705SXin Li     static const bool value = sizeof(f(T())) == 1;
454*67e74705SXin Li   };
455*67e74705SXin Li 
456*67e74705SXin Li   template <class T> bool conv_int2(A<sizeof(f(T()))> p);
457*67e74705SXin Li 
458*67e74705SXin Li   template<typename T> A<sizeof(f(T()))> make_A();
459*67e74705SXin Li 
460*67e74705SXin Li   int a[conv_int<char>::value ? 1 : -1];
461*67e74705SXin Li   bool b = conv_int2<char>(A<1>());
462*67e74705SXin Li   A<1> c = make_A<char>();
463*67e74705SXin Li }
464*67e74705SXin Li 
465*67e74705SXin Li namespace dr340 { // dr340: yes
466*67e74705SXin Li   struct A { A(int); };
467*67e74705SXin Li   struct B { B(A, A, int); };
468*67e74705SXin Li   int x, y;
469*67e74705SXin Li   B b(A(x), A(y), 3);
470*67e74705SXin Li }
471*67e74705SXin Li 
472*67e74705SXin Li namespace dr341 { // dr341: sup 1708
473*67e74705SXin Li   namespace A {
474*67e74705SXin Li     int n;
475*67e74705SXin Li     extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
476*67e74705SXin Li   }
477*67e74705SXin Li   namespace B {
478*67e74705SXin Li     extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}}
479*67e74705SXin Li   }
480*67e74705SXin Li   extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
481*67e74705SXin Li }
482*67e74705SXin Li int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
483*67e74705SXin Li int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
484*67e74705SXin Li int dr341_c; // expected-note {{declared in global scope here}}
485*67e74705SXin Li int dr341_d; // expected-note {{declared in global scope here}}
486*67e74705SXin Li namespace dr341 {
487*67e74705SXin Li   extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
488*67e74705SXin Li   extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
489*67e74705SXin Li 
490*67e74705SXin Li   namespace A { extern "C" int dr341_e; } // expected-note {{previous}}
491*67e74705SXin Li   namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
492*67e74705SXin Li }
493*67e74705SXin Li 
494*67e74705SXin Li // dr342: na
495*67e74705SXin Li 
496*67e74705SXin Li namespace dr343 { // FIXME 343: no
497*67e74705SXin Li   // FIXME: dup 1710
498*67e74705SXin Li   template<typename T> struct A {
499*67e74705SXin Li     template<typename U> struct B {};
500*67e74705SXin Li   };
501*67e74705SXin Li   // FIXME: In these contexts, the 'template' keyword is optional.
502*67e74705SXin Li   template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}}
503*67e74705SXin Li     C() : A<T>::B<T>() {} // expected-error {{use 'template'}}
504*67e74705SXin Li   };
505*67e74705SXin Li }
506*67e74705SXin Li 
507*67e74705SXin Li namespace dr344 { // dr344: dup 1435
508*67e74705SXin Li   struct A { inline virtual ~A(); };
509*67e74705SXin Li   struct B { friend A::~A(); };
510*67e74705SXin Li }
511*67e74705SXin Li 
512*67e74705SXin Li namespace dr345 { // dr345: yes
513*67e74705SXin Li   struct A {
514*67e74705SXin Li     struct X {};
515*67e74705SXin Li     int X; // expected-note {{here}}
516*67e74705SXin Li   };
517*67e74705SXin Li   struct B {
518*67e74705SXin Li     struct X {};
519*67e74705SXin Li   };
520*67e74705SXin Li   template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}}
521*67e74705SXin Li   void f(A a, B b) {
522*67e74705SXin Li     f(b);
523*67e74705SXin Li     f(a); // expected-note {{instantiation}}
524*67e74705SXin Li   }
525*67e74705SXin Li }
526*67e74705SXin Li 
527*67e74705SXin Li // dr346: na
528*67e74705SXin Li 
529*67e74705SXin Li namespace dr347 { // dr347: yes
530*67e74705SXin Li   struct base {
531*67e74705SXin Li     struct nested;
532*67e74705SXin Li     static int n;
533*67e74705SXin Li     static void f();
534*67e74705SXin Li     void g();
535*67e74705SXin Li   };
536*67e74705SXin Li 
537*67e74705SXin Li   struct derived : base {};
538*67e74705SXin Li 
539*67e74705SXin Li   struct derived::nested {}; // expected-error {{no struct named 'nested'}}
540*67e74705SXin Li   int derived::n; // expected-error {{no member named 'n'}}
541*67e74705SXin Li   void derived::f() {} // expected-error {{does not match any}}
542*67e74705SXin Li   void derived::g() {} // expected-error {{does not match any}}
543*67e74705SXin Li }
544*67e74705SXin Li 
545*67e74705SXin Li // dr348: na
546*67e74705SXin Li 
547*67e74705SXin Li namespace dr349 { // dr349: no
548*67e74705SXin Li   struct A {
549*67e74705SXin Li     template <class T> operator T ***() {
550*67e74705SXin Li       int ***p = 0;
551*67e74705SXin Li       return p; // expected-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
552*67e74705SXin Li     }
553*67e74705SXin Li   };
554*67e74705SXin Li 
555*67e74705SXin Li   // FIXME: This is valid.
556*67e74705SXin Li   A a;
557*67e74705SXin Li   const int *const *const *p1 = a; // expected-note {{in instantiation of}}
558*67e74705SXin Li 
559*67e74705SXin Li   struct B {
560*67e74705SXin Li     template <class T> operator T ***() {
561*67e74705SXin Li       const int ***p = 0;
562*67e74705SXin Li       return p;
563*67e74705SXin Li     }
564*67e74705SXin Li   };
565*67e74705SXin Li 
566*67e74705SXin Li   // FIXME: This is invalid.
567*67e74705SXin Li   B b;
568*67e74705SXin Li   const int *const *const *p2 = b;
569*67e74705SXin Li }
570*67e74705SXin Li 
571*67e74705SXin Li // dr351: na
572*67e74705SXin Li 
573*67e74705SXin Li namespace dr352 { // dr352: yes
574*67e74705SXin Li   namespace example1 {
575*67e74705SXin Li     namespace A {
576*67e74705SXin Li       enum E {};
577*67e74705SXin Li       template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}}
578*67e74705SXin Li     }
579*67e74705SXin Li 
580*67e74705SXin Li     template<typename T> void arg(T);
581*67e74705SXin Li     template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
582*67e74705SXin Li 
583*67e74705SXin Li     void f(A::E e) {
584*67e74705SXin Li       foo(e, &arg); // expected-error {{no matching function}}
585*67e74705SXin Li 
586*67e74705SXin Li       using A::foo;
587*67e74705SXin Li       foo<int, int>(e, &arg); // expected-error {{deleted}}
588*67e74705SXin Li     }
589*67e74705SXin Li 
590*67e74705SXin Li     int arg(int);
591*67e74705SXin Li 
592*67e74705SXin Li     void g(A::E e) {
593*67e74705SXin Li       foo(e, &arg); // expected-error {{no matching function}}
594*67e74705SXin Li 
595*67e74705SXin Li       using A::foo;
596*67e74705SXin Li       foo<int, int>(e, &arg); // ok, uses non-template
597*67e74705SXin Li     }
598*67e74705SXin Li   }
599*67e74705SXin Li 
600*67e74705SXin Li   namespace contexts {
601*67e74705SXin Li     template<int I> void f1(int (&)[I]);
602*67e74705SXin Li     template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}}
603*67e74705SXin Li     template<int I> void f3(int (&)[I+1], int (&)[I]);
604*67e74705SXin Li     void f() {
605*67e74705SXin Li       int a[4];
606*67e74705SXin Li       int b[3];
607*67e74705SXin Li       f1(a);
608*67e74705SXin Li       f2(a); // expected-error {{no matching function}}
609*67e74705SXin Li       f3(a, b);
610*67e74705SXin Li     }
611*67e74705SXin Li 
612*67e74705SXin Li     template<int I> struct S {};
613*67e74705SXin Li     template<int I> void g1(S<I>);
614*67e74705SXin Li     template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}}
615*67e74705SXin Li     template<int I> void g3(S<I+1>, S<I>);
616*67e74705SXin Li     void g() {
617*67e74705SXin Li       S<4> a;
618*67e74705SXin Li       S<3> b;
619*67e74705SXin Li       g1(a);
620*67e74705SXin Li       g2(a); // expected-error {{no matching function}}
621*67e74705SXin Li       g3(a, b);
622*67e74705SXin Li     }
623*67e74705SXin Li 
624*67e74705SXin Li     template<typename T> void h1(T = 0); // expected-note {{couldn't infer}}
625*67e74705SXin Li     template<typename T> void h2(T, T = 0);
626*67e74705SXin Li     void h() {
627*67e74705SXin Li       h1(); // expected-error {{no matching function}}
628*67e74705SXin Li       h1(0);
629*67e74705SXin Li       h1<int>();
630*67e74705SXin Li       h2(0);
631*67e74705SXin Li     }
632*67e74705SXin Li 
633*67e74705SXin Li     template<typename T> int tmpl(T);
634*67e74705SXin Li     template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}}
635*67e74705SXin Li     template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}}
636*67e74705SXin Li     void i() {
637*67e74705SXin Li       extern int single(int);
638*67e74705SXin Li       i1(single);
639*67e74705SXin Li       i2(0, 0, single);
640*67e74705SXin Li 
641*67e74705SXin Li       extern int ambig(float), ambig(int);
642*67e74705SXin Li       i1(ambig); // expected-error {{no matching function}}
643*67e74705SXin Li       i2(0, 0, ambig);
644*67e74705SXin Li 
645*67e74705SXin Li       extern void no_match(float), no_match(int);
646*67e74705SXin Li       i1(no_match); // expected-error {{no matching function}}
647*67e74705SXin Li       i2(0, 0, no_match); // expected-error {{no matching function}}
648*67e74705SXin Li 
649*67e74705SXin Li       i1(tmpl); // expected-error {{no matching function}}
650*67e74705SXin Li       i2(0, 0, tmpl);
651*67e74705SXin Li     }
652*67e74705SXin Li   }
653*67e74705SXin Li 
654*67e74705SXin Li   template<typename T> struct is_int;
655*67e74705SXin Li   template<> struct is_int<int> {};
656*67e74705SXin Li 
657*67e74705SXin Li   namespace example2 {
658*67e74705SXin Li     template<typename T> int f(T (*p)(T)) { is_int<T>(); }
659*67e74705SXin Li     int g(int);
660*67e74705SXin Li     int g(char);
661*67e74705SXin Li     int i = f(g);
662*67e74705SXin Li   }
663*67e74705SXin Li 
664*67e74705SXin Li   namespace example3 {
665*67e74705SXin Li     template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
666*67e74705SXin Li     int g(int);
667*67e74705SXin Li     char g(char);
668*67e74705SXin Li     int i = f(1, g);
669*67e74705SXin Li   }
670*67e74705SXin Li 
671*67e74705SXin Li   namespace example4 {
672*67e74705SXin Li     template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
673*67e74705SXin Li     char g(char);
674*67e74705SXin Li     template <class T> T g(T);
675*67e74705SXin Li     int i = f(1, g);
676*67e74705SXin Li   }
677*67e74705SXin Li 
678*67e74705SXin Li   namespace example5 {
679*67e74705SXin Li     template<int I> class A {};
680*67e74705SXin Li     template<int I> void g(A<I+1>); // expected-note {{couldn't infer}}
681*67e74705SXin Li     template<int I> void f(A<I>, A<I+1>);
682*67e74705SXin Li     void h(A<1> a1, A<2> a2) {
683*67e74705SXin Li       g(a1); // expected-error {{no matching function}}
684*67e74705SXin Li       g<0>(a1);
685*67e74705SXin Li       f(a1, a2);
686*67e74705SXin Li     }
687*67e74705SXin Li   }
688*67e74705SXin Li }
689*67e74705SXin Li 
690*67e74705SXin Li // dr353 needs an IRGen test.
691*67e74705SXin Li 
692*67e74705SXin Li namespace dr354 { // dr354: yes c++11
693*67e74705SXin Li   // FIXME: Should we allow this in C++98 too?
694*67e74705SXin Li   struct S {};
695*67e74705SXin Li 
696*67e74705SXin Li   template<int*> struct ptr {}; // expected-note 0-4{{here}}
697*67e74705SXin Li   ptr<0> p0;
698*67e74705SXin Li   ptr<(int*)0> p1;
699*67e74705SXin Li   ptr<(float*)0> p2;
700*67e74705SXin Li   ptr<(int S::*)0> p3;
701*67e74705SXin Li #if __cplusplus < 201103L
702*67e74705SXin Li   // expected-error@-5 {{does not refer to any decl}}
703*67e74705SXin Li   // expected-error@-5 {{does not refer to any decl}}
704*67e74705SXin Li   // expected-error@-5 {{does not refer to any decl}}
705*67e74705SXin Li   // expected-error@-5 {{does not refer to any decl}}
706*67e74705SXin Li #elif __cplusplus <= 201402L
707*67e74705SXin Li   // expected-error@-10 {{must be cast}}
708*67e74705SXin Li   // ok
709*67e74705SXin Li   // expected-error@-10 {{does not match}}
710*67e74705SXin Li   // expected-error@-10 {{does not match}}
711*67e74705SXin Li #else
712*67e74705SXin Li   // expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}}
713*67e74705SXin Li   // ok
714*67e74705SXin Li   // expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}}
715*67e74705SXin Li   // expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}}
716*67e74705SXin Li #endif
717*67e74705SXin Li 
718*67e74705SXin Li   template<int*> int both();
719*67e74705SXin Li   template<int> int both();
720*67e74705SXin Li   int b0 = both<0>();
721*67e74705SXin Li   int b1 = both<(int*)0>();
722*67e74705SXin Li #if __cplusplus < 201103L
723*67e74705SXin Li   // expected-error@-2 {{no matching function}}
724*67e74705SXin Li   // expected-note@-6 {{candidate}}
725*67e74705SXin Li   // expected-note@-6 {{candidate}}
726*67e74705SXin Li #endif
727*67e74705SXin Li 
728*67e74705SXin Li   template<int S::*> struct ptr_mem {}; // expected-note 0-4{{here}}
729*67e74705SXin Li   ptr_mem<0> m0;
730*67e74705SXin Li   ptr_mem<(int S::*)0> m1;
731*67e74705SXin Li   ptr_mem<(float S::*)0> m2;
732*67e74705SXin Li   ptr_mem<(int *)0> m3;
733*67e74705SXin Li #if __cplusplus < 201103L
734*67e74705SXin Li   // expected-error@-5 {{cannot be converted}}
735*67e74705SXin Li   // expected-error@-5 {{is not a pointer to member constant}}
736*67e74705SXin Li   // expected-error@-5 {{cannot be converted}}
737*67e74705SXin Li   // expected-error@-5 {{cannot be converted}}
738*67e74705SXin Li #elif __cplusplus <= 201402L
739*67e74705SXin Li   // expected-error@-10 {{must be cast}}
740*67e74705SXin Li   // ok
741*67e74705SXin Li   // expected-error@-10 {{does not match}}
742*67e74705SXin Li   // expected-error@-10 {{does not match}}
743*67e74705SXin Li #else
744*67e74705SXin Li   // expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}}
745*67e74705SXin Li   // ok
746*67e74705SXin Li   // expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}}
747*67e74705SXin Li   // expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}}
748*67e74705SXin Li #endif
749*67e74705SXin Li }
750*67e74705SXin Li 
751*67e74705SXin Li struct dr355_S; // dr355: yes
752*67e74705SXin Li struct ::dr355_S {}; // expected-warning {{extra qualification}}
753*67e74705SXin Li namespace dr355 { struct ::dr355_S s; }
754*67e74705SXin Li 
755*67e74705SXin Li // dr356: na
756*67e74705SXin Li 
757*67e74705SXin Li namespace dr357 { // dr357: yes
758*67e74705SXin Li   template<typename T> struct A {
759*67e74705SXin Li     void f() const; // expected-note {{const qualified}}
760*67e74705SXin Li   };
761*67e74705SXin Li   template<typename T> void A<T>::f() {} // expected-error {{does not match}}
762*67e74705SXin Li 
763*67e74705SXin Li   struct B {
764*67e74705SXin Li     template<typename T> void f();
765*67e74705SXin Li   };
766*67e74705SXin Li   template<typename T> void B::f() const {} // expected-error {{does not match}}
767*67e74705SXin Li }
768*67e74705SXin Li 
769*67e74705SXin Li namespace dr358 { // dr358: yes
770*67e74705SXin Li   extern "C" void dr358_f();
771*67e74705SXin Li   namespace N {
772*67e74705SXin Li     int var;
773*67e74705SXin Li     extern "C" void dr358_f() { var = 10; }
774*67e74705SXin Li   }
775*67e74705SXin Li }
776*67e74705SXin Li 
777*67e74705SXin Li namespace dr359 { // dr359: yes
778*67e74705SXin Li   // Note, the example in the DR is wrong; it doesn't contain an anonymous
779*67e74705SXin Li   // union.
780*67e74705SXin Li   struct E {
781*67e74705SXin Li     union {
782*67e74705SXin Li       struct {
783*67e74705SXin Li         int x;
784*67e74705SXin Li       } s;
785*67e74705SXin Li     } v;
786*67e74705SXin Li 
787*67e74705SXin Li     union {
788*67e74705SXin Li       struct { // expected-error {{extension}}
789*67e74705SXin Li         int x;
790*67e74705SXin Li       } s;
791*67e74705SXin Li 
792*67e74705SXin Li       struct S { // expected-error {{types cannot be declared in an anonymous union}}
793*67e74705SXin Li         int x;
794*67e74705SXin Li       } t;
795*67e74705SXin Li 
796*67e74705SXin Li       union { // expected-error {{extension}}
797*67e74705SXin Li         int u;
798*67e74705SXin Li       };
799*67e74705SXin Li     };
800*67e74705SXin Li   };
801*67e74705SXin Li }
802*67e74705SXin Li 
803*67e74705SXin Li // dr362: na
804*67e74705SXin Li // dr363: na
805*67e74705SXin Li 
806*67e74705SXin Li namespace dr364 { // dr364: yes
807*67e74705SXin Li   struct S {
808*67e74705SXin Li     static void f(int);
809*67e74705SXin Li     void f(char);
810*67e74705SXin Li   };
811*67e74705SXin Li 
812*67e74705SXin Li   void g() {
813*67e74705SXin Li     S::f('a'); // expected-error {{call to non-static}}
814*67e74705SXin Li     S::f(0);
815*67e74705SXin Li   }
816*67e74705SXin Li }
817*67e74705SXin Li 
818*67e74705SXin Li #if "foo" // expected-error {{invalid token}} dr366: yes
819*67e74705SXin Li #endif
820*67e74705SXin Li 
821*67e74705SXin Li namespace dr367 { // dr367: yes
822*67e74705SXin Li   // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
823*67e74705SXin Li   // array as being a VLA!
824*67e74705SXin Li   int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
825*67e74705SXin Li   int b[true ? 4 : throw 0];
826*67e74705SXin Li   int c[true ? *new int : 4]; // expected-error 2{{variable length array}}
827*67e74705SXin Li   int d[true ? 4 : *new int];
828*67e74705SXin Li #if __cplusplus < 201103L
829*67e74705SXin Li   // expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}}
830*67e74705SXin Li   // expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}}
831*67e74705SXin Li #endif
832*67e74705SXin Li }
833*67e74705SXin Li 
834*67e74705SXin Li namespace dr368 { // dr368: yes
835*67e74705SXin Li   template<typename T, T> struct S {}; // expected-note {{here}}
836*67e74705SXin Li   template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
837*67e74705SXin Li   //template<typename T> int g(S<T, (T())> *); // FIXME: crashes clang
838*67e74705SXin Li   template<typename T> int g(S<T, true ? T() : T()> *); // expected-note {{cannot have type 'dr368::X'}}
839*67e74705SXin Li   struct X {};
840*67e74705SXin Li   int n = g<X>(0); // expected-error {{no matching}}
841*67e74705SXin Li }
842*67e74705SXin Li 
843*67e74705SXin Li // dr370: na
844*67e74705SXin Li 
845*67e74705SXin Li namespace dr372 { // dr372: no
846*67e74705SXin Li   namespace example1 {
847*67e74705SXin Li     template<typename T> struct X {
848*67e74705SXin Li     protected:
849*67e74705SXin Li       typedef T Type; // expected-note 2{{protected}}
850*67e74705SXin Li     };
851*67e74705SXin Li     template<typename T> struct Y {};
852*67e74705SXin Li 
853*67e74705SXin Li     // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
854*67e74705SXin Li     // the protected member T1<T>::Type.
855*67e74705SXin Li     template<typename T,
856*67e74705SXin Li              template<typename> class T1,
857*67e74705SXin Li              template<typename> class T2> struct Z1 :
858*67e74705SXin Li       T1<T>,
859*67e74705SXin Li       T2<typename T1<T>::Type> {}; // expected-error {{protected}}
860*67e74705SXin Li 
861*67e74705SXin Li     template<typename T,
862*67e74705SXin Li              template<typename> class T1,
863*67e74705SXin Li              template<typename> class T2> struct Z2 :
864*67e74705SXin Li       T2<typename T1<T>::Type>, // expected-error {{protected}}
865*67e74705SXin Li       T1<T> {};
866*67e74705SXin Li 
867*67e74705SXin Li     Z1<int, X, Y> z1; // expected-note {{instantiation of}}
868*67e74705SXin Li     Z2<int, X, Y> z2; // expected-note {{instantiation of}}
869*67e74705SXin Li   }
870*67e74705SXin Li 
871*67e74705SXin Li   namespace example2 {
872*67e74705SXin Li     struct X {
873*67e74705SXin Li     private:
874*67e74705SXin Li       typedef int Type; // expected-note {{private}}
875*67e74705SXin Li     };
876*67e74705SXin Li     template<typename T> struct A {
877*67e74705SXin Li       typename T::Type t; // expected-error {{private}}
878*67e74705SXin Li     };
879*67e74705SXin Li     A<X> ax; // expected-note {{instantiation of}}
880*67e74705SXin Li   }
881*67e74705SXin Li 
882*67e74705SXin Li   namespace example3 {
883*67e74705SXin Li     struct A {
884*67e74705SXin Li     protected:
885*67e74705SXin Li       typedef int N; // expected-note 2{{protected}}
886*67e74705SXin Li     };
887*67e74705SXin Li 
888*67e74705SXin Li     template<typename T> struct B {};
889*67e74705SXin Li     template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
890*67e74705SXin Li     template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
891*67e74705SXin Li 
892*67e74705SXin Li     C<A> x; // expected-note {{instantiation of}}
893*67e74705SXin Li     D<A> y; // expected-note {{instantiation of}}
894*67e74705SXin Li   }
895*67e74705SXin Li 
896*67e74705SXin Li   namespace example4 {
897*67e74705SXin Li     class A {
898*67e74705SXin Li       class B {};
899*67e74705SXin Li       friend class X;
900*67e74705SXin Li     };
901*67e74705SXin Li 
902*67e74705SXin Li     struct X : A::B {
903*67e74705SXin Li       A::B mx;
904*67e74705SXin Li       class Y {
905*67e74705SXin Li         A::B my;
906*67e74705SXin Li       };
907*67e74705SXin Li     };
908*67e74705SXin Li   }
909*67e74705SXin Li }
910*67e74705SXin Li 
911*67e74705SXin Li namespace dr373 { // dr373: no
912*67e74705SXin Li   // FIXME: This is valid.
913*67e74705SXin Li   namespace X { int dr373; } // expected-note 2{{here}}
914*67e74705SXin Li   struct dr373 { // expected-note {{here}}
915*67e74705SXin Li     void f() {
916*67e74705SXin Li       using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
917*67e74705SXin Li       int k = dr373; // expected-error {{does not refer to a value}}
918*67e74705SXin Li 
919*67e74705SXin Li       namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
920*67e74705SXin Li       k = Y::dr373;
921*67e74705SXin Li     }
922*67e74705SXin Li   };
923*67e74705SXin Li }
924*67e74705SXin Li 
925*67e74705SXin Li namespace dr374 { // dr374: yes c++11
926*67e74705SXin Li   namespace N {
927*67e74705SXin Li     template<typename T> void f();
928*67e74705SXin Li     template<typename T> struct A { void f(); };
929*67e74705SXin Li   }
930*67e74705SXin Li   template<> void N::f<char>() {}
931*67e74705SXin Li   template<> void N::A<char>::f() {}
932*67e74705SXin Li   template<> struct N::A<int> {};
933*67e74705SXin Li #if __cplusplus < 201103L
934*67e74705SXin Li   // expected-error@-4 {{extension}} expected-note@-7 {{here}}
935*67e74705SXin Li   // expected-error@-4 {{extension}} expected-note@-7 {{here}}
936*67e74705SXin Li   // expected-error@-4 {{extension}} expected-note@-8 {{here}}
937*67e74705SXin Li #endif
938*67e74705SXin Li }
939*67e74705SXin Li 
940*67e74705SXin Li // dr375: dup 345
941*67e74705SXin Li // dr376: na
942*67e74705SXin Li 
943*67e74705SXin Li namespace dr377 { // dr377: yes
944*67e74705SXin Li   enum E { // expected-error {{enumeration values exceed range of largest integer}}
945*67e74705SXin Li     a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
946*67e74705SXin Li     b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
947*67e74705SXin Li   };
948*67e74705SXin Li }
949*67e74705SXin Li 
950*67e74705SXin Li // dr378: dup 276
951*67e74705SXin Li // dr379: na
952*67e74705SXin Li 
953*67e74705SXin Li namespace dr381 { // dr381: yes
954*67e74705SXin Li   struct A {
955*67e74705SXin Li     int a;
956*67e74705SXin Li   };
957*67e74705SXin Li   struct B : virtual A {};
958*67e74705SXin Li   struct C : B {};
959*67e74705SXin Li   struct D : B {};
960*67e74705SXin Li   struct E : public C, public D {};
961*67e74705SXin Li   struct F : public A {};
962*67e74705SXin Li   void f() {
963*67e74705SXin Li     E e;
964*67e74705SXin Li     e.B::a = 0; // expected-error {{ambiguous conversion}}
965*67e74705SXin Li     F f;
966*67e74705SXin Li     f.A::a = 1;
967*67e74705SXin Li   }
968*67e74705SXin Li }
969*67e74705SXin Li 
970*67e74705SXin Li namespace dr382 { // dr382: yes c++11
971*67e74705SXin Li   // FIXME: Should we allow this in C++98 mode?
972*67e74705SXin Li   struct A { typedef int T; };
973*67e74705SXin Li   typename A::T t;
974*67e74705SXin Li   typename dr382::A a;
975*67e74705SXin Li #if __cplusplus < 201103L
976*67e74705SXin Li   // expected-error@-3 {{occurs outside of a template}}
977*67e74705SXin Li   // expected-error@-3 {{occurs outside of a template}}
978*67e74705SXin Li #endif
979*67e74705SXin Li   typename A b; // expected-error {{expected a qualified name}}
980*67e74705SXin Li }
981*67e74705SXin Li 
982*67e74705SXin Li namespace dr383 { // dr383: yes
983*67e74705SXin Li   struct A { A &operator=(const A&); };
984*67e74705SXin Li   struct B { ~B(); };
985*67e74705SXin Li   union C { C &operator=(const C&); };
986*67e74705SXin Li   union D { ~D(); };
987*67e74705SXin Li   int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1];
988*67e74705SXin Li }
989*67e74705SXin Li 
990*67e74705SXin Li namespace dr384 { // dr384: yes
991*67e74705SXin Li   namespace N1 {
992*67e74705SXin Li     template<typename T> struct Base {};
993*67e74705SXin Li     template<typename T> struct X {
994*67e74705SXin Li       struct Y : public Base<T> {
995*67e74705SXin Li         Y operator+(int) const;
996*67e74705SXin Li       };
997*67e74705SXin Li       Y f(unsigned i) { return Y() + i; }
998*67e74705SXin Li     };
999*67e74705SXin Li   }
1000*67e74705SXin Li 
1001*67e74705SXin Li   namespace N2 {
1002*67e74705SXin Li     struct Z {};
1003*67e74705SXin Li     template<typename T> int *operator+(T, unsigned);
1004*67e74705SXin Li   }
1005*67e74705SXin Li 
1006*67e74705SXin Li   int main() {
1007*67e74705SXin Li     N1::X<N2::Z> v;
1008*67e74705SXin Li     v.f(0);
1009*67e74705SXin Li   }
1010*67e74705SXin Li }
1011*67e74705SXin Li 
1012*67e74705SXin Li namespace dr385 { // dr385: yes
1013*67e74705SXin Li   struct A { protected: void f(); };
1014*67e74705SXin Li   struct B : A { using A::f; };
1015*67e74705SXin Li   struct C : A { void g(B b) { b.f(); } };
1016*67e74705SXin Li   void h(B b) { b.f(); }
1017*67e74705SXin Li 
1018*67e74705SXin Li   struct D { int n; }; // expected-note {{member}}
1019*67e74705SXin Li   struct E : protected D {}; // expected-note 2{{protected}}
1020*67e74705SXin Li   struct F : E { friend int i(E); };
1021*67e74705SXin Li   int i(E e) { return e.n; } // expected-error {{protected base}} expected-error {{protected member}}
1022*67e74705SXin Li }
1023*67e74705SXin Li 
1024*67e74705SXin Li namespace dr387 { // dr387: yes
1025*67e74705SXin Li   namespace old {
1026*67e74705SXin Li     template<typename T> class number {
1027*67e74705SXin Li       number(int); // expected-note 2{{here}}
1028*67e74705SXin Li       friend number gcd(number &x, number &y) {}
1029*67e74705SXin Li     };
1030*67e74705SXin Li 
1031*67e74705SXin Li     void g() {
1032*67e74705SXin Li       number<double> a(3), b(4); // expected-error 2{{private}}
1033*67e74705SXin Li       a = gcd(a, b);
1034*67e74705SXin Li       b = gcd(3, 4); // expected-error {{undeclared}}
1035*67e74705SXin Li     }
1036*67e74705SXin Li   }
1037*67e74705SXin Li 
1038*67e74705SXin Li   namespace newer {
1039*67e74705SXin Li     template <typename T> class number {
1040*67e74705SXin Li     public:
1041*67e74705SXin Li       number(int);
1042*67e74705SXin Li       friend number gcd(number x, number y) { return 0; }
1043*67e74705SXin Li     };
1044*67e74705SXin Li 
1045*67e74705SXin Li     void g() {
1046*67e74705SXin Li       number<double> a(3), b(4);
1047*67e74705SXin Li       a = gcd(a, b);
1048*67e74705SXin Li       b = gcd(3, 4); // expected-error {{undeclared}}
1049*67e74705SXin Li     }
1050*67e74705SXin Li   }
1051*67e74705SXin Li }
1052*67e74705SXin Li 
1053*67e74705SXin Li // FIXME: dr388 needs codegen test
1054*67e74705SXin Li 
1055*67e74705SXin Li namespace dr389 { // dr389: no
1056*67e74705SXin Li   struct S {
1057*67e74705SXin Li     typedef struct {} A;
1058*67e74705SXin Li     typedef enum {} B;
1059*67e74705SXin Li     typedef struct {} const C; // expected-note 0-2{{here}}
1060*67e74705SXin Li     typedef enum {} const D; // expected-note 0-1{{here}}
1061*67e74705SXin Li   };
1062*67e74705SXin Li   template<typename> struct T {};
1063*67e74705SXin Li 
1064*67e74705SXin Li   struct WithLinkage1 {};
1065*67e74705SXin Li   enum WithLinkage2 {};
1066*67e74705SXin Li   typedef struct {} *WithLinkage3a, WithLinkage3b;
1067*67e74705SXin Li   typedef enum {} WithLinkage4a, *WithLinkage4b;
1068*67e74705SXin Li   typedef S::A WithLinkage5;
1069*67e74705SXin Li   typedef const S::B WithLinkage6;
1070*67e74705SXin Li   typedef int WithLinkage7;
1071*67e74705SXin Li   typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1072*67e74705SXin Li   typedef T<WithLinkage5> WithLinkage9;
1073*67e74705SXin Li 
1074*67e74705SXin Li   typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}}
1075*67e74705SXin Li   typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}}
1076*67e74705SXin Li   // These two types don't have linkage even though they are externally visible
1077*67e74705SXin Li   // and the ODR requires them to be merged across TUs.
1078*67e74705SXin Li   typedef S::C WithoutLinkage3;
1079*67e74705SXin Li   typedef S::D WithoutLinkage4;
1080*67e74705SXin Li   typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1081*67e74705SXin Li 
1082*67e74705SXin Li #if __cplusplus >= 201103L
1083*67e74705SXin Li   // This has linkage even though its template argument does not.
1084*67e74705SXin Li   // FIXME: This is probably a defect.
1085*67e74705SXin Li   typedef T<WithoutLinkage1> WithLinkage10;
1086*67e74705SXin Li #else
1087*67e74705SXin Li   typedef int WithLinkage10; // dummy
1088*67e74705SXin Li 
1089*67e74705SXin Li   typedef T<WithLinkage1> GoodArg1;
1090*67e74705SXin Li   typedef T<WithLinkage2> GoodArg2;
1091*67e74705SXin Li   typedef T<WithLinkage3a> GoodArg3a;
1092*67e74705SXin Li   typedef T<WithLinkage3b> GoodArg3b;
1093*67e74705SXin Li   typedef T<WithLinkage4a> GoodArg4a;
1094*67e74705SXin Li   typedef T<WithLinkage4b> GoodArg4b;
1095*67e74705SXin Li   typedef T<WithLinkage5> GoodArg5;
1096*67e74705SXin Li   typedef T<WithLinkage6> GoodArg6;
1097*67e74705SXin Li   typedef T<WithLinkage7> GoodArg7;
1098*67e74705SXin Li   typedef T<WithLinkage8> GoodArg8;
1099*67e74705SXin Li   typedef T<WithLinkage9> GoodArg9;
1100*67e74705SXin Li 
1101*67e74705SXin Li   typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}}
1102*67e74705SXin Li   typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}}
1103*67e74705SXin Li   typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}}
1104*67e74705SXin Li   typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}}
1105*67e74705SXin Li   typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}}
1106*67e74705SXin Li #endif
1107*67e74705SXin Li 
1108*67e74705SXin Li   extern WithLinkage1 withLinkage1;
1109*67e74705SXin Li   extern WithLinkage2 withLinkage2;
1110*67e74705SXin Li   extern WithLinkage3a withLinkage3a;
1111*67e74705SXin Li   extern WithLinkage3b withLinkage3b;
1112*67e74705SXin Li   extern WithLinkage4a withLinkage4a;
1113*67e74705SXin Li   extern WithLinkage4b withLinkage4b;
1114*67e74705SXin Li   extern WithLinkage5 withLinkage5;
1115*67e74705SXin Li   extern WithLinkage6 withLinkage6;
1116*67e74705SXin Li   extern WithLinkage7 withLinkage7;
1117*67e74705SXin Li   extern WithLinkage8 withLinkage8;
1118*67e74705SXin Li   extern WithLinkage9 withLinkage9;
1119*67e74705SXin Li   extern WithLinkage10 withLinkage10;
1120*67e74705SXin Li 
1121*67e74705SXin Li   // FIXME: These are all ill-formed.
1122*67e74705SXin Li   extern WithoutLinkage1 withoutLinkage1;
1123*67e74705SXin Li   extern WithoutLinkage2 withoutLinkage2;
1124*67e74705SXin Li   extern WithoutLinkage3 withoutLinkage3;
1125*67e74705SXin Li   extern WithoutLinkage4 withoutLinkage4;
1126*67e74705SXin Li   extern WithoutLinkage5 withoutLinkage5;
1127*67e74705SXin Li 
1128*67e74705SXin Li   // OK, extern "C".
1129*67e74705SXin Li   extern "C" {
1130*67e74705SXin Li     extern WithoutLinkage1 dr389_withoutLinkage1;
1131*67e74705SXin Li     extern WithoutLinkage2 dr389_withoutLinkage2;
1132*67e74705SXin Li     extern WithoutLinkage3 dr389_withoutLinkage3;
1133*67e74705SXin Li     extern WithoutLinkage4 dr389_withoutLinkage4;
1134*67e74705SXin Li     extern WithoutLinkage5 dr389_withoutLinkage5;
1135*67e74705SXin Li   }
1136*67e74705SXin Li 
1137*67e74705SXin Li   // OK, defined.
1138*67e74705SXin Li   WithoutLinkage1 withoutLinkageDef1;
1139*67e74705SXin Li   WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1140*67e74705SXin Li   WithoutLinkage3 withoutLinkageDef3 = {};
1141*67e74705SXin Li   WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1142*67e74705SXin Li   WithoutLinkage5 withoutLinkageDef5;
1143*67e74705SXin Li 
1144*67e74705SXin Li   void use(const void *);
1145*67e74705SXin Li   void use_all() {
1146*67e74705SXin Li     use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1147*67e74705SXin Li     use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1148*67e74705SXin Li     use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1149*67e74705SXin Li 
1150*67e74705SXin Li     use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1151*67e74705SXin Li     use(&withoutLinkage4); use(&withoutLinkage5);
1152*67e74705SXin Li 
1153*67e74705SXin Li     use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2);
1154*67e74705SXin Li     use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4);
1155*67e74705SXin Li     use(&dr389_withoutLinkage5);
1156*67e74705SXin Li 
1157*67e74705SXin Li     use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1158*67e74705SXin Li     use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1159*67e74705SXin Li   }
1160*67e74705SXin Li 
1161*67e74705SXin Li   void local() {
1162*67e74705SXin Li     // FIXME: This is ill-formed.
1163*67e74705SXin Li     extern WithoutLinkage1 withoutLinkageLocal;
1164*67e74705SXin Li   }
1165*67e74705SXin Li }
1166*67e74705SXin Li 
1167*67e74705SXin Li namespace dr390 { // dr390: yes
1168*67e74705SXin Li   template<typename T>
1169*67e74705SXin Li   struct A {
1170*67e74705SXin Li     A() { f(); } // expected-warning {{call to pure virt}}
1171*67e74705SXin Li     virtual void f() = 0; // expected-note {{here}}
1172*67e74705SXin Li     virtual ~A() = 0;
1173*67e74705SXin Li   };
1174*67e74705SXin Li   template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}}
1175*67e74705SXin Li   template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1176*67e74705SXin Li   struct B : A<int> { // expected-note 2{{in instantiation of}}
1177*67e74705SXin Li     void f() {}
1178*67e74705SXin Li   } b;
1179*67e74705SXin Li }
1180*67e74705SXin Li 
1181*67e74705SXin Li namespace dr391 { // dr391: yes c++11
1182*67e74705SXin Li   // FIXME: Should this apply to C++98 too?
1183*67e74705SXin Li   class A { A(const A&); }; // expected-note 0-1{{here}}
1184*67e74705SXin Li   A fa();
1185*67e74705SXin Li   const A &a = fa();
1186*67e74705SXin Li #if __cplusplus < 201103L
1187*67e74705SXin Li   // expected-error@-2 {{C++98 requires an accessible copy constructor}}
1188*67e74705SXin Li #endif
1189*67e74705SXin Li 
1190*67e74705SXin Li   struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
1191*67e74705SXin Li   B fb();
1192*67e74705SXin Li   const B &b = fb();
1193*67e74705SXin Li #if __cplusplus < 201103L
1194*67e74705SXin Li   // expected-error@-2 {{deleted}}
1195*67e74705SXin Li #endif
1196*67e74705SXin Li 
1197*67e74705SXin Li   template<typename T>
1198*67e74705SXin Li   struct C {
1199*67e74705SXin Li     C(const C&) { T::error; }
1200*67e74705SXin Li   };
1201*67e74705SXin Li   C<int> fc();
1202*67e74705SXin Li   const C<int> &c = fc();
1203*67e74705SXin Li }
1204*67e74705SXin Li 
1205*67e74705SXin Li // dr392 FIXME write codegen test
1206*67e74705SXin Li // dr394: na
1207*67e74705SXin Li 
1208*67e74705SXin Li namespace dr395 { // dr395: yes
1209*67e74705SXin Li   struct S {
1210*67e74705SXin Li     template <typename T, int N>(&operator T())[N]; // expected-error {{cannot specify any part of a return type}}
1211*67e74705SXin Li     template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
1212*67e74705SXin Li     template <typename T> operator T *() const { return 0; }
1213*67e74705SXin Li     template <typename T, typename U> operator T U::*() const { return 0; }
1214*67e74705SXin Li     template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}}
1215*67e74705SXin Li   };
1216*67e74705SXin Li 
1217*67e74705SXin Li   struct null1_t {
1218*67e74705SXin Li     template <class T, class U> struct ptr_mem_fun_t {
1219*67e74705SXin Li       typedef T (U::*type)();
1220*67e74705SXin Li     };
1221*67e74705SXin Li 
1222*67e74705SXin Li     template <class T, class U>
1223*67e74705SXin Li     operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}}
1224*67e74705SXin Li       return 0;
1225*67e74705SXin Li     }
1226*67e74705SXin Li   } null1;
1227*67e74705SXin Li   int (S::*p)() = null1; // expected-error {{no viable conversion}}
1228*67e74705SXin Li 
1229*67e74705SXin Li   template <typename T> using id = T; // expected-error 0-1{{extension}}
1230*67e74705SXin Li 
1231*67e74705SXin Li   struct T {
1232*67e74705SXin Li     template <typename T, int N> operator id<T[N]> &();
1233*67e74705SXin Li     template <typename T, typename U> operator id<T (U::*)()>() const;
1234*67e74705SXin Li   };
1235*67e74705SXin Li 
1236*67e74705SXin Li   struct null2_t {
1237*67e74705SXin Li     template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}}
1238*67e74705SXin Li     template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1239*67e74705SXin Li   } null2;
1240*67e74705SXin Li   int (S::*q)() = null2;
1241*67e74705SXin Li }
1242*67e74705SXin Li 
1243*67e74705SXin Li namespace dr396 { // dr396: yes
1244*67e74705SXin Li   void f() {
1245*67e74705SXin Li     auto int a(); // expected-error {{storage class on function}}
1246*67e74705SXin Li     int (i); // expected-note {{previous}}
1247*67e74705SXin Li     auto int (i); // expected-error {{redefinition}}
1248*67e74705SXin Li #if __cplusplus >= 201103L
1249*67e74705SXin Li   // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
1250*67e74705SXin Li #endif
1251*67e74705SXin Li   }
1252*67e74705SXin Li }
1253*67e74705SXin Li 
1254*67e74705SXin Li // dr397: sup 1823
1255*67e74705SXin Li 
1256*67e74705SXin Li namespace dr398 { // dr398: yes
1257*67e74705SXin Li   namespace example1 {
1258*67e74705SXin Li     struct S {
1259*67e74705SXin Li       static int const I = 42;
1260*67e74705SXin Li     };
1261*67e74705SXin Li     template <int N> struct X {};
1262*67e74705SXin Li     template <typename T> void f(X<T::I> *) {}
1263*67e74705SXin Li     template <typename T> void f(X<T::J> *) {}
1264*67e74705SXin Li     void foo() { f<S>(0); }
1265*67e74705SXin Li   }
1266*67e74705SXin Li 
1267*67e74705SXin Li   namespace example2 {
1268*67e74705SXin Li     template <int I> struct X {};
1269*67e74705SXin Li     template <template <class T> class> struct Z {};
1270*67e74705SXin Li     template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}}
1271*67e74705SXin Li     template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}}
1272*67e74705SXin Li     template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}}
1273*67e74705SXin Li     struct A {};
1274*67e74705SXin Li     struct B {
1275*67e74705SXin Li       int Y;
1276*67e74705SXin Li     };
1277*67e74705SXin Li     struct C {
1278*67e74705SXin Li       typedef int N;
1279*67e74705SXin Li     };
1280*67e74705SXin Li     struct D {
1281*67e74705SXin Li       typedef int TT;
1282*67e74705SXin Li     };
1283*67e74705SXin Li 
1284*67e74705SXin Li     void test() {
1285*67e74705SXin Li       f<A>(0); // expected-error {{no matching function}}
1286*67e74705SXin Li       f<B>(0); // expected-error {{no matching function}}
1287*67e74705SXin Li       g<C>(0); // expected-error {{no matching function}}
1288*67e74705SXin Li       h<D>(0); // expected-error {{no matching function}}
1289*67e74705SXin Li     }
1290*67e74705SXin Li   }
1291*67e74705SXin Li }
1292