xref: /aosp_15_r20/external/clang/test/CXX/drs/dr5xx.cpp (revision 67e74705e28f6214e480b399dd47ea732279e315)
1*67e74705SXin Li // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2*67e74705SXin Li // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3*67e74705SXin Li // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4*67e74705SXin Li // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5*67e74705SXin Li 
6*67e74705SXin Li // FIXME: This is included to avoid a diagnostic with no source location
7*67e74705SXin Li // pointing at the implicit operator new. We can't match such a diagnostic
8*67e74705SXin Li // with -verify.
9*67e74705SXin Li __extension__ typedef __SIZE_TYPE__ size_t;
10*67e74705SXin Li void *operator new(size_t); // expected-error 0-1{{missing exception spec}} expected-note{{candidate}}
11*67e74705SXin Li 
12*67e74705SXin Li namespace dr500 { // dr500: dup 372
13*67e74705SXin Li   class D;
14*67e74705SXin Li   class A {
15*67e74705SXin Li     class B;
16*67e74705SXin Li     class C;
17*67e74705SXin Li     friend class D;
18*67e74705SXin Li   };
19*67e74705SXin Li   class A::B {};
20*67e74705SXin Li   class A::C : public A::B {};
21*67e74705SXin Li   class D : public A::B {};
22*67e74705SXin Li }
23*67e74705SXin Li 
24*67e74705SXin Li namespace dr501 { // dr501: yes
25*67e74705SXin Li   struct A {
f()26*67e74705SXin Li     friend void f() {}
gdr501::A27*67e74705SXin Li     void g() {
28*67e74705SXin Li       void (*p)() = &f; // expected-error {{undeclared identifier}}
29*67e74705SXin Li     }
30*67e74705SXin Li   };
31*67e74705SXin Li }
32*67e74705SXin Li 
33*67e74705SXin Li namespace dr502 { // dr502: yes
34*67e74705SXin Li   struct Q {};
35*67e74705SXin Li   template<typename T> struct A {
36*67e74705SXin Li     enum E { e = 1 };
q1dr502::A37*67e74705SXin Li     void q1() { f(e); }
q2dr502::A38*67e74705SXin Li     void q2() { Q arr[sizeof(E)]; f(arr); }
q3dr502::A39*67e74705SXin Li     void q3() { Q arr[e]; f(arr); }
sanitydr502::A40*67e74705SXin Li     void sanity() { Q arr[1]; f(arr); } // expected-error {{undeclared identifier 'f'}}
41*67e74705SXin Li   };
42*67e74705SXin Li   int f(A<int>::E);
43*67e74705SXin Li   template<int N> int f(Q (&)[N]);
44*67e74705SXin Li   template struct A<int>;
45*67e74705SXin Li }
46*67e74705SXin Li 
47*67e74705SXin Li namespace dr505 { // dr505: yes
48*67e74705SXin Li   const char *exts = "\e\(\{\[\%"; // expected-error 5{{use of non-standard escape}}
49*67e74705SXin Li   const char *unknown = "\Q"; // expected-error {{unknown escape sequence}}
50*67e74705SXin Li }
51*67e74705SXin Li 
52*67e74705SXin Li namespace dr506 { // dr506: yes
53*67e74705SXin Li   struct NonPod { ~NonPod(); };
54*67e74705SXin Li   void f(...);
g(NonPod np)55*67e74705SXin Li   void g(NonPod np) { f(np); } // expected-error {{cannot pass}}
56*67e74705SXin Li }
57*67e74705SXin Li 
58*67e74705SXin Li // FIXME: Add tests here once DR260 is resolved.
59*67e74705SXin Li // dr507: dup 260
60*67e74705SXin Li 
61*67e74705SXin Li // dr508: na
62*67e74705SXin Li // dr509: na
63*67e74705SXin Li // dr510: na
64*67e74705SXin Li 
65*67e74705SXin Li namespace dr512 { // dr512: yes
66*67e74705SXin Li   struct A {
67*67e74705SXin Li     A(int);
68*67e74705SXin Li   };
69*67e74705SXin Li   union U { A a; };
70*67e74705SXin Li #if __cplusplus < 201103L
71*67e74705SXin Li   // expected-error@-2 {{has a non-trivial constructor}}
72*67e74705SXin Li   // expected-note@-6 {{no default constructor}}
73*67e74705SXin Li   // expected-note@-6 {{suppressed by user-declared constructor}}
74*67e74705SXin Li #endif
75*67e74705SXin Li }
76*67e74705SXin Li 
77*67e74705SXin Li // dr513: na
78*67e74705SXin Li 
79*67e74705SXin Li namespace dr514 { // dr514: yes
80*67e74705SXin Li   namespace A { extern int x, y; }
81*67e74705SXin Li   int A::x = y;
82*67e74705SXin Li }
83*67e74705SXin Li 
84*67e74705SXin Li namespace dr515 { // dr515: sup 1017
85*67e74705SXin Li   // FIXME: dr1017 reverses the wording of dr515, but the current draft has
86*67e74705SXin Li   // dr515's wording, with a different fix for dr1017.
87*67e74705SXin Li 
88*67e74705SXin Li   struct X { int n; };
89*67e74705SXin Li   template<typename T> struct Y : T {
fdr515::Y90*67e74705SXin Li     int f() { return X::n; }
91*67e74705SXin Li   };
92*67e74705SXin Li   int k = Y<X>().f();
93*67e74705SXin Li 
94*67e74705SXin Li   struct A { int a; };
fdr515::B95*67e74705SXin Li   struct B { void f() { int k = sizeof(A::a); } };
96*67e74705SXin Li #if __cplusplus < 201103L
97*67e74705SXin Li   // expected-error@-2 {{invalid use of non-static data member}}
98*67e74705SXin Li #endif
99*67e74705SXin Li }
100*67e74705SXin Li 
101*67e74705SXin Li // dr516: na
102*67e74705SXin Li 
103*67e74705SXin Li namespace dr517 { // dr517: no
104*67e74705SXin Li   // This is NDR, but we should diagnose it anyway.
105*67e74705SXin Li   template<typename T> struct S {};
106*67e74705SXin Li   template<typename T> int v = 0; // expected-error 0-1{{extension}}
107*67e74705SXin Li 
108*67e74705SXin Li   template struct S<int*>;
109*67e74705SXin Li   template int v<int*>;
110*67e74705SXin Li 
111*67e74705SXin Li   S<char&> s;
112*67e74705SXin Li   int k = v<char&>;
113*67e74705SXin Li 
114*67e74705SXin Li   // FIXME: These are both ill-formed.
115*67e74705SXin Li   template<typename T> struct S<T*> {};
116*67e74705SXin Li   template<typename T> int v<T*> = 0; // expected-error 0-1{{extension}}
117*67e74705SXin Li 
118*67e74705SXin Li   // FIXME: These are both ill-formed.
119*67e74705SXin Li   template<typename T> struct S<T&> {};
120*67e74705SXin Li   template<typename T> int v<T&> = 0; // expected-error 0-1{{extension}}
121*67e74705SXin Li }
122*67e74705SXin Li 
123*67e74705SXin Li namespace dr518 { // dr518: yes c++11
124*67e74705SXin Li   enum E { e, };
125*67e74705SXin Li #if __cplusplus < 201103L
126*67e74705SXin Li   // expected-error@-2 {{C++11 extension}}
127*67e74705SXin Li #endif
128*67e74705SXin Li }
129*67e74705SXin Li 
130*67e74705SXin Li namespace dr519 { // dr519: yes
131*67e74705SXin Li // FIXME: Add a codegen test.
132*67e74705SXin Li #if __cplusplus >= 201103L
133*67e74705SXin Li #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
134*67e74705SXin Li   int test[fold((int*)(void*)0) ? -1 : 1];
135*67e74705SXin Li #undef fold
136*67e74705SXin Li #endif
137*67e74705SXin Li }
138*67e74705SXin Li 
139*67e74705SXin Li // dr520: na
140*67e74705SXin Li 
141*67e74705SXin Li // dr521: no
142*67e74705SXin Li // FIXME: The wording here is broken. It's not reasonable to expect a
143*67e74705SXin Li // diagnostic here. Once the relevant DR gets a number, mark this as a dup.
144*67e74705SXin Li 
145*67e74705SXin Li namespace dr522 { // dr522: yes
146*67e74705SXin Li   struct S {};
147*67e74705SXin Li   template<typename T> void b1(volatile T &);
148*67e74705SXin Li   template<typename T> void b2(volatile T * const *);
149*67e74705SXin Li   template<typename T> void b2(volatile T * const S::*);
150*67e74705SXin Li   template<typename T> void b2(volatile T * const S::* const *);
151*67e74705SXin Li   template<typename T> void b2a(volatile T *S::* const *); // expected-note {{candidate template ignored: deduced type 'volatile int *dr522::S::*const *' of 1st parameter does not match adjusted type 'int *dr522::S::**' of argument}}
152*67e74705SXin Li 
153*67e74705SXin Li   template<typename T> struct Base {};
154*67e74705SXin Li   struct Derived : Base<int> {};
155*67e74705SXin Li   template<typename T> void b3(Base<T>);
156*67e74705SXin Li   template<typename T> void b3(Base<T> *);
157*67e74705SXin Li 
test(int n,const int cn,int ** p,int * S::* pm)158*67e74705SXin Li   void test(int n, const int cn, int **p, int *S::*pm) {
159*67e74705SXin Li     int *a[3], *S::*am[3];
160*67e74705SXin Li     const Derived cd = Derived();
161*67e74705SXin Li     Derived d[3];
162*67e74705SXin Li 
163*67e74705SXin Li     b1(n);
164*67e74705SXin Li     b1(cn);
165*67e74705SXin Li     b2(p);
166*67e74705SXin Li     b2(pm);
167*67e74705SXin Li     b2(a);
168*67e74705SXin Li     b2(am);
169*67e74705SXin Li     b2a(am); // expected-error {{no matching function}}
170*67e74705SXin Li     b3(d);
171*67e74705SXin Li     b3(cd);
172*67e74705SXin Li   }
173*67e74705SXin Li }
174*67e74705SXin Li 
175*67e74705SXin Li namespace dr524 { // dr524: yes
f(T a,T b)176*67e74705SXin Li   template<typename T> void f(T a, T b) { operator+(a, b); } // expected-error {{call}}
177*67e74705SXin Li 
178*67e74705SXin Li   struct S {};
179*67e74705SXin Li   void operator+(S, S);
180*67e74705SXin Li   template void f(S, S);
181*67e74705SXin Li 
182*67e74705SXin Li   namespace N { struct S {}; }
183*67e74705SXin Li   void operator+(N::S, N::S); // expected-note {{should be declared}}
184*67e74705SXin Li   template void f(N::S, N::S); // expected-note {{instantiation}}
185*67e74705SXin Li }
186*67e74705SXin Li 
187*67e74705SXin Li namespace dr525 { // dr525: yes
188*67e74705SXin Li   namespace before {
189*67e74705SXin Li     // Note, the example was correct prior to the change; instantiation is
190*67e74705SXin Li     // required for cases like this:
191*67e74705SXin Li     template <class T> struct D { operator T*(); };
g(D<double> ppp)192*67e74705SXin Li     void g(D<double> ppp) {
193*67e74705SXin Li       delete ppp;
194*67e74705SXin Li     }
195*67e74705SXin Li   }
196*67e74705SXin Li   namespace after {
197*67e74705SXin Li     template <class T> struct D { typename T::error e; }; // expected-error {{prior to '::'}}
g(D<double> * ppp)198*67e74705SXin Li     void g(D<double> *ppp) {
199*67e74705SXin Li       delete ppp; // expected-note {{instantiation of}}
200*67e74705SXin Li     }
201*67e74705SXin Li   }
202*67e74705SXin Li }
203*67e74705SXin Li 
204*67e74705SXin Li namespace dr526 { // dr526: yes
205*67e74705SXin Li   template<int> struct S {};
206*67e74705SXin Li   template<int N> void f1(S<N> s);
207*67e74705SXin Li   template<int N> void f2(S<(N)> s); // expected-note {{couldn't infer}}
208*67e74705SXin Li   template<int N> void f3(S<+N> s); // expected-note {{couldn't infer}}
209*67e74705SXin Li   template<int N> void g1(int (&)[N]);
210*67e74705SXin Li   template<int N> void g2(int (&)[(N)]); // expected-note {{couldn't infer}}
211*67e74705SXin Li   template<int N> void g3(int (&)[+N]); // expected-note {{couldn't infer}}
212*67e74705SXin Li 
test(int (& a)[3],S<3> s)213*67e74705SXin Li   void test(int (&a)[3], S<3> s) {
214*67e74705SXin Li     f1(s);
215*67e74705SXin Li     f2(s); // expected-error {{no matching}}
216*67e74705SXin Li     f3(s); // expected-error {{no matching}}
217*67e74705SXin Li     g1(a);
218*67e74705SXin Li     g2(a); // expected-error {{no matching}}
219*67e74705SXin Li     g3(a); // expected-error {{no matching}}
220*67e74705SXin Li   }
221*67e74705SXin Li 
222*67e74705SXin Li   template<int N> struct X {
223*67e74705SXin Li     typedef int type;
224*67e74705SXin Li     X<N>::type v1;
225*67e74705SXin Li     X<(N)>::type v2; // expected-error {{missing 'typename'}}
226*67e74705SXin Li     X<+N>::type v3; // expected-error {{missing 'typename'}}
227*67e74705SXin Li   };
228*67e74705SXin Li }
229*67e74705SXin Li 
230*67e74705SXin Li namespace dr527 { // dr527: na
231*67e74705SXin Li   // This DR is meaningless. It removes a required diagnostic from the case
232*67e74705SXin Li   // where a not-externally-visible object is odr-used but not defined, which
233*67e74705SXin Li   // requires a diagnostic for a different reason.
234*67e74705SXin Li   extern struct { int x; } a; // FIXME: We should reject this, per dr389.
235*67e74705SXin Li   static struct { int x; } b;
236*67e74705SXin Li   extern "C" struct { int x; } c;
237*67e74705SXin Li   namespace { extern struct { int x; } d; }
238*67e74705SXin Li   typedef struct { int x; } *P;
239*67e74705SXin Li   struct E { static P e; }; // FIXME: We should reject this, per dr389.
240*67e74705SXin Li   namespace { struct F { static P f; }; }
241*67e74705SXin Li 
242*67e74705SXin Li   int ax = a.x, bx = b.x, cx = c.x, dx = d.x, ex = E::e->x, fx = F::f->x;
243*67e74705SXin Li }
244*67e74705SXin Li 
245*67e74705SXin Li namespace dr530 { // dr530: yes
246*67e74705SXin Li   template<int*> struct S { enum { N = 1 }; };
247*67e74705SXin Li   template<void(*)()> struct T { enum { N = 1 }; };
248*67e74705SXin Li   int n;
249*67e74705SXin Li   void f();
250*67e74705SXin Li   int a[S<&n>::N];
251*67e74705SXin Li   int b[T<&f>::N];
252*67e74705SXin Li }
253*67e74705SXin Li 
254*67e74705SXin Li namespace dr531 { // dr531: partial
255*67e74705SXin Li   namespace good {
256*67e74705SXin Li     template<typename T> struct A {
fdr531::good::A257*67e74705SXin Li       void f(T) { T::error; }
gdr531::good::A258*67e74705SXin Li       template<typename U> void g(T, U) { T::error; }
259*67e74705SXin Li       struct B { typename T::error error; };
260*67e74705SXin Li       template<typename U> struct C { typename T::error error; };
261*67e74705SXin Li       static T n;
262*67e74705SXin Li     };
263*67e74705SXin Li     template<typename T> T A<T>::n = T::error;
264*67e74705SXin Li 
f(int)265*67e74705SXin Li     template<> void A<int>::f(int) {}
g(int,U)266*67e74705SXin Li     template<> template<typename U> void A<int>::g(int, U) {}
267*67e74705SXin Li     template<> struct A<int>::B {};
268*67e74705SXin Li     template<> template<typename U> struct A<int>::C {};
269*67e74705SXin Li     template<> int A<int>::n = 0;
270*67e74705SXin Li 
use(A<int> a)271*67e74705SXin Li     void use(A<int> a) {
272*67e74705SXin Li       a.f(a.n);
273*67e74705SXin Li       a.g(0, 0);
274*67e74705SXin Li       A<int>::B b;
275*67e74705SXin Li       A<int>::C<int> c;
276*67e74705SXin Li     }
277*67e74705SXin Li 
278*67e74705SXin Li     template<> struct A<char> {
279*67e74705SXin Li       void f(char);
280*67e74705SXin Li       template<typename U> void g(char, U);
281*67e74705SXin Li       struct B;
282*67e74705SXin Li       template<typename U> struct C;
283*67e74705SXin Li       static char n;
284*67e74705SXin Li     };
285*67e74705SXin Li 
f(char)286*67e74705SXin Li     void A<char>::f(char) {}
g(char,U)287*67e74705SXin Li     template<typename U> void A<char>::g(char, U) {}
288*67e74705SXin Li     struct A<char>::B {};
289*67e74705SXin Li     template<typename U> struct A<char>::C {};
290*67e74705SXin Li     char A<char>::n = 0;
291*67e74705SXin Li   }
292*67e74705SXin Li 
293*67e74705SXin Li   namespace bad {
294*67e74705SXin Li     template<typename T> struct A {
fdr531::bad::A295*67e74705SXin Li       void f(T) { T::error; }
gdr531::bad::A296*67e74705SXin Li       template<typename U> void g(T, U) { T::error; }
297*67e74705SXin Li       struct B { typename T::error error; };
298*67e74705SXin Li       template<typename U> struct C { typename T::error error; }; // expected-note {{here}}
299*67e74705SXin Li       static T n;
300*67e74705SXin Li     };
301*67e74705SXin Li     template<typename T> T A<T>::n = T::error;
302*67e74705SXin Li 
f(int)303*67e74705SXin Li     void A<int>::f(int) {} // expected-error {{requires 'template<>'}}
g(int,U)304*67e74705SXin Li     template<typename U> void A<int>::g(int, U) {} // expected-error {{should be empty}}
305*67e74705SXin Li     struct A<int>::B {}; // expected-error {{requires 'template<>'}}
306*67e74705SXin Li     template<typename U> struct A<int>::C {}; // expected-error {{should be empty}} expected-error {{different kind of symbol}}
307*67e74705SXin Li     int A<int>::n = 0; // expected-error {{requires 'template<>'}}
308*67e74705SXin Li 
309*67e74705SXin Li     template<> struct A<char> { // expected-note 2{{here}}
310*67e74705SXin Li       void f(char);
311*67e74705SXin Li       template<typename U> void g(char, U);
312*67e74705SXin Li       struct B; // expected-note {{here}}
313*67e74705SXin Li       template<typename U> struct C;
314*67e74705SXin Li       static char n;
315*67e74705SXin Li     };
316*67e74705SXin Li 
f(char)317*67e74705SXin Li     template<> void A<char>::f(char) {} // expected-error {{no function template matches}}
318*67e74705SXin Li     // FIXME: This is ill-formed; -pedantic-errors should reject.
g(char,U)319*67e74705SXin Li     template<> template<typename U> void A<char>::g(char, U) {} // expected-warning {{extraneous template parameter list}}
320*67e74705SXin Li     template<> struct A<char>::B {}; // expected-error {{extraneous 'template<>'}} expected-error {{does not specialize}}
321*67e74705SXin Li     // FIXME: This is ill-formed; -pedantic-errors should reject.
322*67e74705SXin Li     template<> template<typename U> struct A<char>::C {}; // expected-warning {{extraneous template parameter list}}
323*67e74705SXin Li     template<> char A<char>::n = 0; // expected-error {{extraneous 'template<>'}}
324*67e74705SXin Li   }
325*67e74705SXin Li 
326*67e74705SXin Li   namespace nested {
327*67e74705SXin Li     template<typename T> struct A {
328*67e74705SXin Li       template<typename U> struct B;
329*67e74705SXin Li     };
330*67e74705SXin Li     template<> template<typename U> struct A<int>::B {
331*67e74705SXin Li       void f();
332*67e74705SXin Li       void g();
333*67e74705SXin Li       template<typename V> void h();
334*67e74705SXin Li       template<typename V> void i();
335*67e74705SXin Li     };
f()336*67e74705SXin Li     template<> template<typename U> void A<int>::B<U>::f() {}
g()337*67e74705SXin Li     template<typename U> void A<int>::B<U>::g() {} // expected-error {{should be empty}}
338*67e74705SXin Li 
h()339*67e74705SXin Li     template<> template<typename U> template<typename V> void A<int>::B<U>::h() {}
i()340*67e74705SXin Li     template<typename U> template<typename V> void A<int>::B<U>::i() {} // expected-error {{should be empty}}
341*67e74705SXin Li 
f()342*67e74705SXin Li     template<> template<> void A<int>::B<int>::f() {}
h()343*67e74705SXin Li     template<> template<> template<typename V> void A<int>::B<int>::h() {}
h()344*67e74705SXin Li     template<> template<> template<> void A<int>::B<int>::h<int>() {}
345*67e74705SXin Li 
f()346*67e74705SXin Li     template<> void A<int>::B<char>::f() {} // expected-error {{requires 'template<>'}}
h()347*67e74705SXin Li     template<> template<typename V> void A<int>::B<char>::h() {} // expected-error {{should be empty}}
348*67e74705SXin Li   }
349*67e74705SXin Li }
350*67e74705SXin Li 
351*67e74705SXin Li // PR8130
352*67e74705SXin Li namespace dr532 { // dr532: 3.5
353*67e74705SXin Li   struct A { };
354*67e74705SXin Li 
355*67e74705SXin Li   template<class T> struct B {
356*67e74705SXin Li     template<class R> int &operator*(R&);
357*67e74705SXin Li   };
358*67e74705SXin Li 
359*67e74705SXin Li   template<class T, class R> float &operator*(T&, R&);
test()360*67e74705SXin Li   void test() {
361*67e74705SXin Li     A a;
362*67e74705SXin Li     B<A> b;
363*67e74705SXin Li     int &ir = b * a;
364*67e74705SXin Li   }
365*67e74705SXin Li }
366*67e74705SXin Li 
367*67e74705SXin Li // dr533: na
368*67e74705SXin Li 
369*67e74705SXin Li namespace dr534 { // dr534: yes
370*67e74705SXin Li   struct S {};
371*67e74705SXin Li   template<typename T> void operator+(S, T);
372*67e74705SXin Li   template<typename T> void operator+<T*>(S, T*) {} // expected-error {{function template partial spec}}
373*67e74705SXin Li }
374*67e74705SXin Li 
375*67e74705SXin Li namespace dr535 { // dr535: yes
376*67e74705SXin Li   class X { private: X(const X&); };
377*67e74705SXin Li   struct A {
378*67e74705SXin Li     X x;
379*67e74705SXin Li     template<typename T> A(T&);
380*67e74705SXin Li   };
381*67e74705SXin Li   struct B : A {
382*67e74705SXin Li     X y;
383*67e74705SXin Li     B(volatile A&);
384*67e74705SXin Li   };
385*67e74705SXin Li 
386*67e74705SXin Li   extern A a1;
387*67e74705SXin Li   A a2(a1); // ok, uses constructor template
388*67e74705SXin Li 
389*67e74705SXin Li   extern volatile B b1;
390*67e74705SXin Li   B b2(b1); // ok, uses converting constructor
391*67e74705SXin Li 
f()392*67e74705SXin Li   void f() { throw a1; }
393*67e74705SXin Li 
394*67e74705SXin Li #if __cplusplus >= 201103L
395*67e74705SXin Li   struct C {
Cdr535::C396*67e74705SXin Li     constexpr C() : n(0) {}
Cdr535::C397*67e74705SXin Li     template<typename T> constexpr C(T&t) : n(t.n == 0 ? throw 0 : 0) {}
398*67e74705SXin Li     int n;
399*67e74705SXin Li   };
c()400*67e74705SXin Li   constexpr C c() { return C(); }
401*67e74705SXin Li   // ok, copy is elided
402*67e74705SXin Li   constexpr C x = c();
403*67e74705SXin Li #endif
404*67e74705SXin Li }
405*67e74705SXin Li 
406*67e74705SXin Li // dr537: na
407*67e74705SXin Li // dr538: na
408*67e74705SXin Li 
409*67e74705SXin Li // dr539: yes
dr539(const a)410*67e74705SXin Li const dr539( // expected-error {{requires a type specifier}}
411*67e74705SXin Li     const a) { // expected-error {{unknown type name 'a'}}
412*67e74705SXin Li   const b; // expected-error {{requires a type specifier}}
413*67e74705SXin Li   new const; // expected-error {{expected a type}}
414*67e74705SXin Li   try {} catch (const n) {} // expected-error {{unknown type name 'n'}}
415*67e74705SXin Li   try {} catch (const) {} // expected-error {{expected a type}}
416*67e74705SXin Li   if (const n = 0) {} // expected-error {{requires a type specifier}}
417*67e74705SXin Li   switch (const n = 0) {} // expected-error {{requires a type specifier}}
418*67e74705SXin Li   while (const n = 0) {} // expected-error {{requires a type specifier}}
419*67e74705SXin Li   for (const n = 0; // expected-error {{requires a type specifier}}
420*67e74705SXin Li        const m = 0; ) {} // expected-error {{requires a type specifier}}
421*67e74705SXin Li   sizeof(const); // expected-error {{requires a type specifier}}
422*67e74705SXin Li   struct S {
423*67e74705SXin Li     const n; // expected-error {{requires a type specifier}}
424*67e74705SXin Li     operator const(); // expected-error {{expected a type}}
425*67e74705SXin Li   };
426*67e74705SXin Li #if __cplusplus >= 201103L
427*67e74705SXin Li   int arr[3];
428*67e74705SXin Li   // FIXME: The extra braces here are to avoid the parser getting too
429*67e74705SXin Li   // badly confused when recovering here. We should fix this recovery.
430*67e74705SXin Li   { for (const n // expected-error {{unknown type name 'n'}} expected-note {{}}
431*67e74705SXin Li          : arr) ; {} } // expected-error +{{}}
432*67e74705SXin Li   (void) [](const) {}; // expected-error {{requires a type specifier}}
433*67e74705SXin Li   (void) [](const n) {}; // expected-error {{unknown type name 'n'}}
434*67e74705SXin Li   enum E : const {}; // expected-error {{expected a type}}
435*67e74705SXin Li   using T = const; // expected-error {{expected a type}}
436*67e74705SXin Li   auto f() -> const; // expected-error {{expected a type}}
437*67e74705SXin Li #endif
438*67e74705SXin Li }
439*67e74705SXin Li 
440*67e74705SXin Li namespace dr540 { // dr540: yes
441*67e74705SXin Li   typedef int &a;
442*67e74705SXin Li   typedef const a &a; // expected-warning {{has no effect}}
443*67e74705SXin Li   typedef const int &b;
444*67e74705SXin Li   typedef b &b;
445*67e74705SXin Li   typedef const a &c; // expected-note {{previous}} expected-warning {{has no effect}}
446*67e74705SXin Li   typedef const b &c; // expected-error {{different}} expected-warning {{has no effect}}
447*67e74705SXin Li }
448*67e74705SXin Li 
449*67e74705SXin Li namespace dr541 { // dr541: yes
450*67e74705SXin Li   template<int> struct X { typedef int type; };
451*67e74705SXin Li   template<typename T> struct S {
452*67e74705SXin Li     int f(T);
453*67e74705SXin Li 
454*67e74705SXin Li     int g(int);
455*67e74705SXin Li     T g(bool);
456*67e74705SXin Li 
457*67e74705SXin Li     int h();
458*67e74705SXin Li     int h(T);
459*67e74705SXin Li 
xdr541::S460*67e74705SXin Li     void x() {
461*67e74705SXin Li       // These are type-dependent expressions, even though we could
462*67e74705SXin Li       // determine that all calls have type 'int'.
463*67e74705SXin Li       X<sizeof(f(0))>::type a; // expected-error +{{}}
464*67e74705SXin Li       X<sizeof(g(0))>::type b; // expected-error +{{}}
465*67e74705SXin Li       X<sizeof(h(0))>::type b; // expected-error +{{}}
466*67e74705SXin Li 
467*67e74705SXin Li       typename X<sizeof(f(0))>::type a;
468*67e74705SXin Li       typename X<sizeof(h(0))>::type b;
469*67e74705SXin Li     }
470*67e74705SXin Li   };
471*67e74705SXin Li }
472*67e74705SXin Li 
473*67e74705SXin Li namespace dr542 { // dr542: yes
474*67e74705SXin Li #if __cplusplus >= 201103L
475*67e74705SXin Li   struct A { A() = delete; int n; };
476*67e74705SXin Li   A a[32] = {}; // ok, constructor not called
477*67e74705SXin Li 
478*67e74705SXin Li   struct B {
479*67e74705SXin Li     int n;
480*67e74705SXin Li   private:
481*67e74705SXin Li     B() = default;
482*67e74705SXin Li   };
483*67e74705SXin Li   B b[32] = {}; // ok, constructor not called
484*67e74705SXin Li #endif
485*67e74705SXin Li }
486*67e74705SXin Li 
487*67e74705SXin Li namespace dr543 { // dr543: yes
488*67e74705SXin Li   // In C++98+DR543, this is valid because value-initialization doesn't call a
489*67e74705SXin Li   // trivial default constructor, so we never notice that defining the
490*67e74705SXin Li   // constructor would be ill-formed.
491*67e74705SXin Li   //
492*67e74705SXin Li   // In C++11+DR543, this is ill-formed, because the default constructor is
493*67e74705SXin Li   // deleted, and value-initialization *does* call a deleted default
494*67e74705SXin Li   // constructor, even if it is trivial.
495*67e74705SXin Li   struct A {
496*67e74705SXin Li     const int n;
497*67e74705SXin Li   };
498*67e74705SXin Li   A a = A();
499*67e74705SXin Li #if __cplusplus >= 201103L
500*67e74705SXin Li   // expected-error@-2 {{deleted}}
501*67e74705SXin Li   // expected-note@-5 {{would not be initialized}}
502*67e74705SXin Li #endif
503*67e74705SXin Li }
504*67e74705SXin Li 
505*67e74705SXin Li namespace dr544 { // dr544: yes
506*67e74705SXin Li   int *n;
507*67e74705SXin Li 
508*67e74705SXin Li   template<class T> struct A { int n; };
509*67e74705SXin Li   template<class T> struct B : A<T> { int get(); };
get()510*67e74705SXin Li   template<> int B<int>::get() { return n; }
511*67e74705SXin Li   int k = B<int>().get();
512*67e74705SXin Li }
513*67e74705SXin Li 
514*67e74705SXin Li namespace dr546 { // dr546: yes
515*67e74705SXin Li   template<typename T> struct A { void f(); };
516*67e74705SXin Li   template struct A<int>;
f()517*67e74705SXin Li   template<typename T> void A<T>::f() { T::error; }
518*67e74705SXin Li }
519*67e74705SXin Li 
520*67e74705SXin Li namespace dr547 { // dr547: yes
521*67e74705SXin Li   template<typename T> struct X;
522*67e74705SXin Li   template<typename T> struct X<T() const> {};
f(T C::*)523*67e74705SXin Li   template<typename T, typename C> X<T> f(T C::*) { return X<T>(); }
524*67e74705SXin Li 
525*67e74705SXin Li   struct S { void f() const; };
526*67e74705SXin Li   X<void() const> x = f(&S::f);
527*67e74705SXin Li }
528*67e74705SXin Li 
529*67e74705SXin Li namespace dr548 { // dr548: dup 482
530*67e74705SXin Li   template<typename T> struct S {};
f()531*67e74705SXin Li   template<typename T> void f() {}
532*67e74705SXin Li   template struct dr548::S<int>;
533*67e74705SXin Li   template void dr548::f<int>();
534*67e74705SXin Li }
535*67e74705SXin Li 
536*67e74705SXin Li namespace dr551 { // dr551: yes c++11
537*67e74705SXin Li   // FIXME: This obviously should apply in C++98 mode too.
f()538*67e74705SXin Li   template<typename T> void f() {}
539*67e74705SXin Li   template inline void f<int>();
540*67e74705SXin Li #if __cplusplus >= 201103L
541*67e74705SXin Li   // expected-error@-2 {{cannot be 'inline'}}
542*67e74705SXin Li #endif
543*67e74705SXin Li 
g()544*67e74705SXin Li   template<typename T> inline void g() {}
545*67e74705SXin Li   template inline void g<int>();
546*67e74705SXin Li #if __cplusplus >= 201103L
547*67e74705SXin Li   // expected-error@-2 {{cannot be 'inline'}}
548*67e74705SXin Li #endif
549*67e74705SXin Li 
550*67e74705SXin Li   template<typename T> struct X {
fdr551::X551*67e74705SXin Li     void f() {}
552*67e74705SXin Li   };
553*67e74705SXin Li   template inline void X<int>::f();
554*67e74705SXin Li #if __cplusplus >= 201103L
555*67e74705SXin Li   // expected-error@-2 {{cannot be 'inline'}}
556*67e74705SXin Li #endif
557*67e74705SXin Li }
558*67e74705SXin Li 
559*67e74705SXin Li namespace dr552 { // dr552: yes
560*67e74705SXin Li   template<typename T, typename T::U> struct X {};
561*67e74705SXin Li   struct Y { typedef int U; };
562*67e74705SXin Li   X<Y, 0> x;
563*67e74705SXin Li }
564*67e74705SXin Li 
565*67e74705SXin Li struct dr553_class {
566*67e74705SXin Li   friend void *operator new(size_t, dr553_class);
567*67e74705SXin Li };
568*67e74705SXin Li namespace dr553 {
569*67e74705SXin Li   dr553_class c;
570*67e74705SXin Li   // Contrary to the apparent intention of the DR, operator new is not actually
571*67e74705SXin Li   // looked up with a lookup mechanism that performs ADL; the standard says it
572*67e74705SXin Li   // "is looked up in global scope", where it is not visible.
573*67e74705SXin Li   void *p = new (c) int; // expected-error {{no matching function}}
574*67e74705SXin Li 
575*67e74705SXin Li   struct namespace_scope {
576*67e74705SXin Li     friend void *operator new(size_t, namespace_scope); // expected-error {{cannot be declared inside a namespace}}
577*67e74705SXin Li   };
578*67e74705SXin Li }
579*67e74705SXin Li 
580*67e74705SXin Li // dr556: na
581*67e74705SXin Li 
582*67e74705SXin Li namespace dr557 { // dr557: yes
583*67e74705SXin Li   template<typename T> struct S {
584*67e74705SXin Li     friend void f(S<T> *);
585*67e74705SXin Li     friend void g(S<S<T> > *);
586*67e74705SXin Li   };
x(S<int> * p,S<S<int>> * q)587*67e74705SXin Li   void x(S<int> *p, S<S<int> > *q) {
588*67e74705SXin Li     f(p);
589*67e74705SXin Li     g(q);
590*67e74705SXin Li   }
591*67e74705SXin Li }
592*67e74705SXin Li 
593*67e74705SXin Li namespace dr558 { // dr558: yes
594*67e74705SXin Li   wchar_t a = L'\uD7FF';
595*67e74705SXin Li   wchar_t b = L'\xD7FF';
596*67e74705SXin Li   wchar_t c = L'\uD800'; // expected-error {{invalid universal character}}
597*67e74705SXin Li   wchar_t d = L'\xD800';
598*67e74705SXin Li   wchar_t e = L'\uDFFF'; // expected-error {{invalid universal character}}
599*67e74705SXin Li   wchar_t f = L'\xDFFF';
600*67e74705SXin Li   wchar_t g = L'\uE000';
601*67e74705SXin Li   wchar_t h = L'\xE000';
602*67e74705SXin Li }
603*67e74705SXin Li 
604*67e74705SXin Li template<typename> struct dr559 { typedef int T; dr559::T u; }; // dr559: yes
605*67e74705SXin Li 
606*67e74705SXin Li namespace dr561 { // dr561: yes
607*67e74705SXin Li   template<typename T> void f(int);
g(T t)608*67e74705SXin Li   template<typename T> void g(T t) {
609*67e74705SXin Li     f<T>(t);
610*67e74705SXin Li   }
611*67e74705SXin Li   namespace {
612*67e74705SXin Li     struct S {};
613*67e74705SXin Li     template<typename T> static void f(S);
614*67e74705SXin Li   }
h(S s)615*67e74705SXin Li   void h(S s) {
616*67e74705SXin Li     g(s);
617*67e74705SXin Li   }
618*67e74705SXin Li }
619*67e74705SXin Li 
620*67e74705SXin Li namespace dr564 { // dr564: yes
621*67e74705SXin Li   extern "C++" void f(int);
622*67e74705SXin Li   void f(int); // ok
623*67e74705SXin Li   extern "C++" { extern int n; }
624*67e74705SXin Li   int n; // ok
625*67e74705SXin Li }
626*67e74705SXin Li 
627*67e74705SXin Li namespace dr565 { // dr565: yes
628*67e74705SXin Li   namespace N {
629*67e74705SXin Li     template<typename T> int f(T); // expected-note {{target}}
630*67e74705SXin Li   }
631*67e74705SXin Li   using N::f; // expected-note {{using}}
632*67e74705SXin Li   template<typename T> int f(T*);
633*67e74705SXin Li   template<typename T> void f(T);
634*67e74705SXin Li   template<typename T, int = 0> int f(T); // expected-error 0-1{{extension}}
635*67e74705SXin Li   template<typename T> int f(T, int = 0);
636*67e74705SXin Li   template<typename T> int f(T); // expected-error {{conflicts with}}
637*67e74705SXin Li }
638*67e74705SXin Li 
639*67e74705SXin Li namespace dr566 { // dr566: yes
640*67e74705SXin Li #if __cplusplus >= 201103L
641*67e74705SXin Li   int check[int(-3.99) == -3 ? 1 : -1];
642*67e74705SXin Li #endif
643*67e74705SXin Li }
644*67e74705SXin Li 
645*67e74705SXin Li // dr567: na
646*67e74705SXin Li 
647*67e74705SXin Li namespace dr568 { // dr568: yes c++11
648*67e74705SXin Li   // FIXME: This is a DR issue against C++98, so should probably apply there
649*67e74705SXin Li   // too.
650*67e74705SXin Li   struct x { int y; };
651*67e74705SXin Li   class trivial : x {
652*67e74705SXin Li     x y;
653*67e74705SXin Li   public:
654*67e74705SXin Li     int n;
655*67e74705SXin Li   };
656*67e74705SXin Li   int check_trivial[__is_trivial(trivial) ? 1 : -1];
657*67e74705SXin Li 
658*67e74705SXin Li   struct std_layout {
659*67e74705SXin Li     std_layout();
660*67e74705SXin Li     std_layout(const std_layout &);
661*67e74705SXin Li     ~std_layout();
662*67e74705SXin Li   private:
663*67e74705SXin Li     int n;
664*67e74705SXin Li   };
665*67e74705SXin Li   int check_std_layout[__is_standard_layout(std_layout) ? 1 : -1];
666*67e74705SXin Li 
667*67e74705SXin Li   struct aggregate {
668*67e74705SXin Li     int x;
669*67e74705SXin Li     int y;
670*67e74705SXin Li     trivial t;
671*67e74705SXin Li     std_layout sl;
672*67e74705SXin Li   };
673*67e74705SXin Li   aggregate aggr = {};
674*67e74705SXin Li 
675*67e74705SXin Li   void f(...);
g(trivial t)676*67e74705SXin Li   void g(trivial t) { f(t); }
677*67e74705SXin Li #if __cplusplus < 201103L
678*67e74705SXin Li   // expected-error@-2 {{non-POD}}
679*67e74705SXin Li #endif
680*67e74705SXin Li 
jump()681*67e74705SXin Li   void jump() {
682*67e74705SXin Li     goto x;
683*67e74705SXin Li #if __cplusplus < 201103L
684*67e74705SXin Li     // expected-error@-2 {{cannot jump}}
685*67e74705SXin Li     // expected-note@+2 {{non-POD}}
686*67e74705SXin Li #endif
687*67e74705SXin Li     trivial t;
688*67e74705SXin Li   x: ;
689*67e74705SXin Li   }
690*67e74705SXin Li }
691*67e74705SXin Li 
692*67e74705SXin Li namespace dr569 { // dr569: yes c++11
693*67e74705SXin Li   // FIXME: This is a DR issue against C++98, so should probably apply there
694*67e74705SXin Li   // too.
695*67e74705SXin Li   ;;;;;
696*67e74705SXin Li #if __cplusplus < 201103L
697*67e74705SXin Li   // expected-error@-2 {{C++11 extension}}
698*67e74705SXin Li #endif
699*67e74705SXin Li }
700*67e74705SXin Li 
701*67e74705SXin Li namespace dr570 { // dr570: dup 633
702*67e74705SXin Li   int n;
703*67e74705SXin Li   int &r = n; // expected-note {{previous}}
704*67e74705SXin Li   int &r = n; // expected-error {{redefinition}}
705*67e74705SXin Li }
706*67e74705SXin Li 
707*67e74705SXin Li namespace dr571 { // dr571 unknown
708*67e74705SXin Li   // FIXME: Add a codegen test.
709*67e74705SXin Li   typedef int &ir;
710*67e74705SXin Li   int n;
711*67e74705SXin Li   const ir r = n; // expected-warning {{has no effect}} FIXME: Test if this has internal linkage.
712*67e74705SXin Li }
713*67e74705SXin Li 
714*67e74705SXin Li namespace dr572 { // dr572: yes
715*67e74705SXin Li   enum E { a = 1, b = 2 };
716*67e74705SXin Li   int check[a + b == 3 ? 1 : -1];
717*67e74705SXin Li }
718*67e74705SXin Li 
719*67e74705SXin Li namespace dr573 { // dr573: no
720*67e74705SXin Li   void *a;
721*67e74705SXin Li   int *b = reinterpret_cast<int*>(a);
722*67e74705SXin Li   void (*c)() = reinterpret_cast<void(*)()>(a);
723*67e74705SXin Li   void *d = reinterpret_cast<void*>(c);
724*67e74705SXin Li #if __cplusplus < 201103L
725*67e74705SXin Li   // expected-error@-3 {{extension}}
726*67e74705SXin Li   // expected-error@-3 {{extension}}
727*67e74705SXin Li #endif
f()728*67e74705SXin Li   void f() { delete a; } // expected-error {{cannot delete}}
729*67e74705SXin Li   int n = d - a; // expected-error {{arithmetic on pointers to void}}
730*67e74705SXin Li   // FIXME: This is ill-formed.
731*67e74705SXin Li   template<void*> struct S;
732*67e74705SXin Li   template<int*> struct T;
733*67e74705SXin Li }
734*67e74705SXin Li 
735*67e74705SXin Li namespace dr574 { // dr574: yes
736*67e74705SXin Li   struct A {
737*67e74705SXin Li     A &operator=(const A&) const; // expected-note {{does not match because it is const}}
738*67e74705SXin Li   };
739*67e74705SXin Li   struct B {
740*67e74705SXin Li     B &operator=(const B&) volatile; // expected-note {{nearly matches}}
741*67e74705SXin Li   };
742*67e74705SXin Li #if __cplusplus >= 201103L
743*67e74705SXin Li   struct C {
744*67e74705SXin Li     C &operator=(const C&) &; // expected-note {{not viable}} expected-note {{nearly matches}} expected-note {{here}}
745*67e74705SXin Li   };
746*67e74705SXin Li   struct D {
747*67e74705SXin Li     D &operator=(const D&) &&; // expected-note {{not viable}} expected-note {{nearly matches}} expected-note {{here}}
748*67e74705SXin Li   };
test(C c,D d)749*67e74705SXin Li   void test(C c, D d) {
750*67e74705SXin Li     c = c;
751*67e74705SXin Li     C() = c; // expected-error {{no viable}}
752*67e74705SXin Li     d = d; // expected-error {{no viable}}
753*67e74705SXin Li     D() = d;
754*67e74705SXin Li   }
755*67e74705SXin Li #endif
756*67e74705SXin Li   struct Test {
757*67e74705SXin Li     friend A &A::operator=(const A&); // expected-error {{does not match}}
758*67e74705SXin Li     friend B &B::operator=(const B&); // expected-error {{does not match}}
759*67e74705SXin Li #if __cplusplus >= 201103L
760*67e74705SXin Li     // FIXME: We shouldn't produce the 'cannot overload' diagnostics here.
761*67e74705SXin Li     friend C &C::operator=(const C&); // expected-error {{does not match}} expected-error {{cannot overload}}
762*67e74705SXin Li     friend D &D::operator=(const D&); // expected-error {{does not match}} expected-error {{cannot overload}}
763*67e74705SXin Li #endif
764*67e74705SXin Li   };
765*67e74705SXin Li }
766*67e74705SXin Li 
767*67e74705SXin Li namespace dr575 { // dr575: yes
768*67e74705SXin Li   template<typename T, typename U = typename T::type> void a(T); void a(...); // expected-error 0-1{{extension}}
769*67e74705SXin Li   template<typename T, typename T::type U = 0> void b(T); void b(...); // expected-error 0-1{{extension}}
770*67e74705SXin Li   template<typename T, int U = T::value> void c(T); void c(...); // expected-error 0-1{{extension}}
771*67e74705SXin Li   template<typename T> void d(T, int = T::value); void d(...); // expected-error {{cannot be used prior to '::'}}
x()772*67e74705SXin Li   void x() {
773*67e74705SXin Li     a(0);
774*67e74705SXin Li     b(0);
775*67e74705SXin Li     c(0);
776*67e74705SXin Li     d(0); // expected-note {{in instantiation of default function argument}}
777*67e74705SXin Li   }
778*67e74705SXin Li 
779*67e74705SXin Li   template<typename T = int&> void f(T* = 0); // expected-error 0-1{{extension}}
780*67e74705SXin Li   template<typename T = int> void f(T = 0); // expected-error 0-1{{extension}}
g()781*67e74705SXin Li   void g() { f<>(); }
782*67e74705SXin Li 
783*67e74705SXin Li   template<typename T> T &h(T *);
784*67e74705SXin Li   template<typename T> T *h(T *);
785*67e74705SXin Li   void *p = h((void*)0);
786*67e74705SXin Li }
787*67e74705SXin Li 
788*67e74705SXin Li namespace dr576 { // dr576: yes
789*67e74705SXin Li   typedef void f() {} // expected-error {{function definition declared 'typedef'}}
790*67e74705SXin Li   void f(typedef int n); // expected-error {{invalid storage class}}
f(char c)791*67e74705SXin Li   void f(char c) { typedef int n; }
792*67e74705SXin Li }
793*67e74705SXin Li 
794*67e74705SXin Li namespace dr577 { // dr577: yes
795*67e74705SXin Li   typedef void V;
796*67e74705SXin Li   typedef const void CV;
797*67e74705SXin Li   void a(void);
798*67e74705SXin Li   void b(const void); // expected-error {{qualifiers}}
799*67e74705SXin Li   void c(V);
800*67e74705SXin Li   void d(CV); // expected-error {{qualifiers}}
801*67e74705SXin Li   void (*e)(void) = c;
802*67e74705SXin Li   void (*f)(const void); // expected-error {{qualifiers}}
803*67e74705SXin Li   void (*g)(V) = a;
804*67e74705SXin Li   void (*h)(CV); // expected-error {{qualifiers}}
805*67e74705SXin Li   template<typename T> void i(T); // expected-note 2{{requires 1 arg}}
806*67e74705SXin Li   template<typename T> void j(void (*)(T)); // expected-note 2{{argument may not have 'void' type}}
k()807*67e74705SXin Li   void k() {
808*67e74705SXin Li     a();
809*67e74705SXin Li     c();
810*67e74705SXin Li     i<void>(); // expected-error {{no match}}
811*67e74705SXin Li     i<const void>(); // expected-error {{no match}}
812*67e74705SXin Li     j<void>(0); // expected-error {{no match}}
813*67e74705SXin Li     j<const void>(0); // expected-error {{no match}}
814*67e74705SXin Li   }
815*67e74705SXin Li }
816*67e74705SXin Li 
817*67e74705SXin Li namespace dr580 { // dr580: partial
818*67e74705SXin Li   class C;
819*67e74705SXin Li   struct A { static C c; };
820*67e74705SXin Li   struct B { static C c; };
821*67e74705SXin Li   class C {
822*67e74705SXin Li     C(); // expected-note {{here}}
823*67e74705SXin Li     ~C(); // expected-note {{here}}
824*67e74705SXin Li 
825*67e74705SXin Li     typedef int I; // expected-note 2{{here}}
826*67e74705SXin Li     template<int> struct X;
827*67e74705SXin Li     template<int> friend struct Y;
828*67e74705SXin Li     template<int> void f();
829*67e74705SXin Li     template<int> friend void g();
830*67e74705SXin Li     friend struct A;
831*67e74705SXin Li   };
832*67e74705SXin Li 
833*67e74705SXin Li   template<C::I> struct C::X {};
834*67e74705SXin Li   template<C::I> struct Y {};
835*67e74705SXin Li   template<C::I> struct Z {}; // expected-error {{private}}
836*67e74705SXin Li 
837*67e74705SXin Li   struct C2 {
838*67e74705SXin Li     class X {
839*67e74705SXin Li       struct A;
840*67e74705SXin Li       typedef int I;
841*67e74705SXin Li       friend struct A;
842*67e74705SXin Li     };
843*67e74705SXin Li     class Y {
844*67e74705SXin Li       template<X::I> struct A {}; // FIXME: We incorrectly accept this
845*67e74705SXin Li                                   // because we think C2::Y::A<...> might
846*67e74705SXin Li                                   // instantiate to C2::X::A
847*67e74705SXin Li     };
848*67e74705SXin Li   };
849*67e74705SXin Li 
f()850*67e74705SXin Li   template<C::I> void C::f() {}
g()851*67e74705SXin Li   template<C::I> void g() {}
h()852*67e74705SXin Li   template<C::I> void h() {} // expected-error {{private}}
853*67e74705SXin Li 
854*67e74705SXin Li   C A::c;
855*67e74705SXin Li   C B::c; // expected-error 2{{private}}
856*67e74705SXin Li }
857*67e74705SXin Li 
858*67e74705SXin Li // dr582: na
859*67e74705SXin Li 
860*67e74705SXin Li namespace dr583 { // dr583: no
861*67e74705SXin Li   // see n3624
862*67e74705SXin Li   int *p;
863*67e74705SXin Li   // FIXME: These are all ill-formed.
864*67e74705SXin Li   bool b1 = p < 0;
865*67e74705SXin Li   bool b2 = p > 0;
866*67e74705SXin Li   bool b3 = p <= 0;
867*67e74705SXin Li   bool b4 = p >= 0;
868*67e74705SXin Li }
869*67e74705SXin Li 
870*67e74705SXin Li // dr584: na
871*67e74705SXin Li 
872*67e74705SXin Li namespace dr585 { // dr585: yes
873*67e74705SXin Li   template<typename> struct T;
874*67e74705SXin Li   struct A {
875*67e74705SXin Li     friend T; // expected-error {{requires a type specifier}} expected-error {{can only be classes or functions}}
876*67e74705SXin Li     // FIXME: It's not clear whether the standard allows this or what it means,
877*67e74705SXin Li     // but the DR585 writeup suggests it as an alternative.
878*67e74705SXin Li     template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
879*67e74705SXin Li   };
880*67e74705SXin Li   template<template<typename> class T> struct B {
881*67e74705SXin Li     friend T; // expected-error {{requires a type specifier}} expected-error {{can only be classes or functions}}
882*67e74705SXin Li     template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
883*67e74705SXin Li   };
884*67e74705SXin Li }
885*67e74705SXin Li 
886*67e74705SXin Li // dr586: na
887*67e74705SXin Li 
888*67e74705SXin Li namespace dr587 { // dr587: yes
f(bool b,const T x,T y)889*67e74705SXin Li   template<typename T> void f(bool b, const T x, T y) {
890*67e74705SXin Li     const T *p = &(b ? x : y);
891*67e74705SXin Li   }
892*67e74705SXin Li   struct S {};
893*67e74705SXin Li   template void f(bool, const int, int);
894*67e74705SXin Li   template void f(bool, const S, S);
895*67e74705SXin Li }
896*67e74705SXin Li 
897*67e74705SXin Li namespace dr588 { // dr588: yes
898*67e74705SXin Li   struct A { int n; }; // expected-note {{ambiguous}}
f()899*67e74705SXin Li   template<typename T> int f() {
900*67e74705SXin Li     struct S : A, T { int f() { return n; } } s;
901*67e74705SXin Li     int a = s.f();
902*67e74705SXin Li     int b = s.n; // expected-error {{found in multiple}}
903*67e74705SXin Li   }
904*67e74705SXin Li   struct B { int n; }; // expected-note {{ambiguous}}
905*67e74705SXin Li   int k = f<B>(); // expected-note {{here}}
906*67e74705SXin Li }
907*67e74705SXin Li 
908*67e74705SXin Li namespace dr589 { // dr589: yes
909*67e74705SXin Li   struct B { };
910*67e74705SXin Li   struct D : B { };
911*67e74705SXin Li   D f();
912*67e74705SXin Li   extern const B &b;
913*67e74705SXin Li   bool a;
914*67e74705SXin Li   const B *p = &(a ? f() : b); // expected-error {{temporary}}
915*67e74705SXin Li   const B *q = &(a ? D() : b); // expected-error {{temporary}}
916*67e74705SXin Li }
917*67e74705SXin Li 
918*67e74705SXin Li namespace dr590 { // dr590: yes
919*67e74705SXin Li   template<typename T> struct A {
920*67e74705SXin Li     struct B {
921*67e74705SXin Li       struct C {
922*67e74705SXin Li         A<T>::B::C f(A<T>::B::C); // ok, no 'typename' required.
923*67e74705SXin Li       };
924*67e74705SXin Li     };
925*67e74705SXin Li   };
f(A<T>::B::C)926*67e74705SXin Li   template<typename T> typename A<T>::B::C A<T>::B::C::f(A<T>::B::C) {}
927*67e74705SXin Li }
928*67e74705SXin Li 
929*67e74705SXin Li namespace dr591 { // dr591: no
930*67e74705SXin Li   template<typename T> struct A {
931*67e74705SXin Li     typedef int M;
932*67e74705SXin Li     struct B {
933*67e74705SXin Li       typedef void M;
934*67e74705SXin Li       struct C;
935*67e74705SXin Li     };
936*67e74705SXin Li   };
937*67e74705SXin Li 
938*67e74705SXin Li   template<typename T> struct A<T>::B::C : A<T> {
939*67e74705SXin Li     // FIXME: Should find member of non-dependent base class A<T>.
940*67e74705SXin Li     M m; // expected-error {{incomplete type 'M' (aka 'void'}}
941*67e74705SXin Li   };
942*67e74705SXin Li }
943*67e74705SXin Li 
944*67e74705SXin Li // dr592: na
945*67e74705SXin Li // dr593 needs an IRGen test.
946*67e74705SXin Li // dr594: na
947*67e74705SXin Li 
948*67e74705SXin Li namespace dr595 { // dr595: dup 1330
949*67e74705SXin Li   template<class T> struct X {
fdr595::X950*67e74705SXin Li     void f() throw(T) {}
951*67e74705SXin Li   };
952*67e74705SXin Li   struct S {
953*67e74705SXin Li     X<S> xs;
954*67e74705SXin Li   };
955*67e74705SXin Li }
956*67e74705SXin Li 
957*67e74705SXin Li // dr597: na
958*67e74705SXin Li 
959*67e74705SXin Li namespace dr598 { // dr598: yes
960*67e74705SXin Li   namespace N {
961*67e74705SXin Li     void f(int);
962*67e74705SXin Li     void f(char);
963*67e74705SXin Li     // Not found by ADL.
964*67e74705SXin Li     void g(void (*)(int));
965*67e74705SXin Li     void h(void (*)(int));
966*67e74705SXin Li 
967*67e74705SXin Li     namespace M {
968*67e74705SXin Li       struct S {};
969*67e74705SXin Li       int &h(void (*)(S));
970*67e74705SXin Li     }
971*67e74705SXin Li     void i(M::S);
972*67e74705SXin Li     void i();
973*67e74705SXin Li   }
974*67e74705SXin Li   int &g(void(*)(char));
975*67e74705SXin Li   int &r = g(N::f);
976*67e74705SXin Li   int &s = h(N::f); // expected-error {{undeclared}}
977*67e74705SXin Li   int &t = h(N::i);
978*67e74705SXin Li }
979*67e74705SXin Li 
980*67e74705SXin Li namespace dr599 { // dr599: partial
981*67e74705SXin Li   typedef int Fn();
982*67e74705SXin Li   struct S { operator void*(); };
983*67e74705SXin Li   struct T { operator Fn*(); };
984*67e74705SXin Li   struct U { operator int*(); operator void*(); }; // expected-note 2{{conversion}}
985*67e74705SXin Li   struct V { operator int*(); operator Fn*(); };
f(void * p,void (* q)(),S s,T t,U u,V v)986*67e74705SXin Li   void f(void *p, void (*q)(), S s, T t, U u, V v) {
987*67e74705SXin Li     delete p; // expected-error {{cannot delete}}
988*67e74705SXin Li     delete q; // expected-error {{cannot delete}}
989*67e74705SXin Li     delete s; // expected-error {{cannot delete}}
990*67e74705SXin Li     delete t; // expected-error {{cannot delete}}
991*67e74705SXin Li     // FIXME: This is valid, but is rejected due to a non-conforming GNU
992*67e74705SXin Li     // extension allowing deletion of pointers to void.
993*67e74705SXin Li     delete u; // expected-error {{ambiguous}}
994*67e74705SXin Li     delete v;
995*67e74705SXin Li   }
996*67e74705SXin Li }
997