xref: /minix3/external/bsd/llvm/dist/clang/test/CXX/drs/dr4xx.cpp (revision 0a6a1f1d05b60e214de2f05a7310ddd1f0e590e7)
1*0a6a1f1dSLionel Sambuc // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2*0a6a1f1dSLionel Sambuc // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3*0a6a1f1dSLionel Sambuc // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4*0a6a1f1dSLionel Sambuc // RUN: env ASAN_OPTIONS=detect_stack_use_after_return=0 %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5*0a6a1f1dSLionel Sambuc 
6*0a6a1f1dSLionel Sambuc // FIXME: __SIZE_TYPE__ expands to 'long long' on some targets.
7*0a6a1f1dSLionel Sambuc __extension__ typedef __SIZE_TYPE__ size_t;
8*0a6a1f1dSLionel Sambuc 
9*0a6a1f1dSLionel Sambuc namespace std { struct type_info; }
10*0a6a1f1dSLionel Sambuc 
11*0a6a1f1dSLionel Sambuc namespace dr400 { // dr400: yes
12*0a6a1f1dSLionel Sambuc   struct A { int a; struct a {}; }; // expected-note 2{{conflicting}} expected-note {{ambiguous}}
13*0a6a1f1dSLionel Sambuc   struct B { int a; struct a {}; }; // expected-note 2{{target}} expected-note {{ambiguous}}
14*0a6a1f1dSLionel Sambuc   struct C : A, B { using A::a; struct a b; };
15*0a6a1f1dSLionel Sambuc   struct D : A, B { using A::a; using B::a; struct a b; }; // expected-error 2{{conflicts}}
16*0a6a1f1dSLionel Sambuc   struct E : A, B { struct a b; }; // expected-error {{found in multiple base classes}}
17*0a6a1f1dSLionel Sambuc }
18*0a6a1f1dSLionel Sambuc 
19*0a6a1f1dSLionel Sambuc namespace dr401 { // dr401: yes
20*0a6a1f1dSLionel Sambuc   template<class T, class U = typename T::type> class A : public T {}; // expected-error {{protected}} expected-error 2{{private}}
21*0a6a1f1dSLionel Sambuc 
22*0a6a1f1dSLionel Sambuc   class B {
23*0a6a1f1dSLionel Sambuc   protected:
24*0a6a1f1dSLionel Sambuc     typedef int type; // expected-note {{protected}}
25*0a6a1f1dSLionel Sambuc   };
26*0a6a1f1dSLionel Sambuc 
27*0a6a1f1dSLionel Sambuc   class C {
28*0a6a1f1dSLionel Sambuc     typedef int type; // expected-note {{private}}
29*0a6a1f1dSLionel Sambuc     friend class A<C>; // expected-note {{default argument}}
30*0a6a1f1dSLionel Sambuc   };
31*0a6a1f1dSLionel Sambuc 
32*0a6a1f1dSLionel Sambuc   class D {
33*0a6a1f1dSLionel Sambuc     typedef int type; // expected-note {{private}}
34*0a6a1f1dSLionel Sambuc     friend class A<D, int>;
35*0a6a1f1dSLionel Sambuc   };
36*0a6a1f1dSLionel Sambuc 
37*0a6a1f1dSLionel Sambuc   A<B> *b; // expected-note {{default argument}}
38*0a6a1f1dSLionel Sambuc   // FIXME: We're missing the "in instantiation of" note for the default
39*0a6a1f1dSLionel Sambuc   // argument here.
40*0a6a1f1dSLionel Sambuc   A<D> *d;
41*0a6a1f1dSLionel Sambuc 
42*0a6a1f1dSLionel Sambuc   struct E {
43*0a6a1f1dSLionel Sambuc     template<class T, class U = typename T::type> class A : public T {};
44*0a6a1f1dSLionel Sambuc   };
45*0a6a1f1dSLionel Sambuc   class F {
46*0a6a1f1dSLionel Sambuc     typedef int type;
47*0a6a1f1dSLionel Sambuc     friend class E;
48*0a6a1f1dSLionel Sambuc   };
49*0a6a1f1dSLionel Sambuc   E::A<F> eaf; // ok, default argument is in befriended context
50*0a6a1f1dSLionel Sambuc 
51*0a6a1f1dSLionel Sambuc   // FIXME: Why do we get different diagnostics in C++11 onwards here? We seem
52*0a6a1f1dSLionel Sambuc   // to not treat the default template argument as a SFINAE context in C++98.
f(T)53*0a6a1f1dSLionel Sambuc   template<class T, class U = typename T::type> void f(T) {}
g(B b)54*0a6a1f1dSLionel Sambuc   void g(B b) { f(b); }
55*0a6a1f1dSLionel Sambuc #if __cplusplus < 201103L
56*0a6a1f1dSLionel Sambuc   // expected-error@-3 0-1{{extension}} expected-error@-3 {{protected}} expected-note@-3 {{instantiation}}
57*0a6a1f1dSLionel Sambuc   // expected-note@-3 {{substituting}}
58*0a6a1f1dSLionel Sambuc #else
59*0a6a1f1dSLionel Sambuc   // expected-error@-5 {{no matching}} expected-note@-6 {{protected}}
60*0a6a1f1dSLionel Sambuc #endif
61*0a6a1f1dSLionel Sambuc }
62*0a6a1f1dSLionel Sambuc 
63*0a6a1f1dSLionel Sambuc namespace dr403 { // dr403: yes
64*0a6a1f1dSLionel Sambuc   namespace A {
65*0a6a1f1dSLionel Sambuc     struct S {};
66*0a6a1f1dSLionel Sambuc     int f(void*);
67*0a6a1f1dSLionel Sambuc   }
68*0a6a1f1dSLionel Sambuc   template<typename T> struct X {};
69*0a6a1f1dSLionel Sambuc   typedef struct X<A::S>::X XS;
70*0a6a1f1dSLionel Sambuc   XS *p;
71*0a6a1f1dSLionel Sambuc   int k = f(p); // ok, finds A::f, even though type XS is a typedef-name
72*0a6a1f1dSLionel Sambuc                 // referring to an elaborated-type-specifier naming a
73*0a6a1f1dSLionel Sambuc                 // injected-class-name, which is about as far from a
74*0a6a1f1dSLionel Sambuc                 // template-id as we can make it.
75*0a6a1f1dSLionel Sambuc }
76*0a6a1f1dSLionel Sambuc 
77*0a6a1f1dSLionel Sambuc // dr404: na
78*0a6a1f1dSLionel Sambuc // (NB: also sup 594)
79*0a6a1f1dSLionel Sambuc 
80*0a6a1f1dSLionel Sambuc namespace dr406 { // dr406: yes
81*0a6a1f1dSLionel Sambuc   typedef struct {
82*0a6a1f1dSLionel Sambuc     static int n; // expected-error {{static data member 'n' not allowed in anonymous struct}}
83*0a6a1f1dSLionel Sambuc   } A;
84*0a6a1f1dSLionel Sambuc }
85*0a6a1f1dSLionel Sambuc 
86*0a6a1f1dSLionel Sambuc namespace dr407 { // dr407: no
87*0a6a1f1dSLionel Sambuc   struct S;
88*0a6a1f1dSLionel Sambuc   typedef struct S S;
f()89*0a6a1f1dSLionel Sambuc   void f() {
90*0a6a1f1dSLionel Sambuc     struct S *p;
91*0a6a1f1dSLionel Sambuc     {
92*0a6a1f1dSLionel Sambuc       typedef struct S S; // expected-note {{here}}
93*0a6a1f1dSLionel Sambuc       struct S *p; // expected-error {{refers to a typedef}}
94*0a6a1f1dSLionel Sambuc     }
95*0a6a1f1dSLionel Sambuc   }
96*0a6a1f1dSLionel Sambuc   struct S {};
97*0a6a1f1dSLionel Sambuc 
98*0a6a1f1dSLionel Sambuc   namespace UsingDir {
99*0a6a1f1dSLionel Sambuc     namespace A {
100*0a6a1f1dSLionel Sambuc       struct S {}; // expected-note {{found}}
101*0a6a1f1dSLionel Sambuc     }
102*0a6a1f1dSLionel Sambuc     namespace B {
103*0a6a1f1dSLionel Sambuc       typedef int S; // expected-note {{found}}
104*0a6a1f1dSLionel Sambuc     }
105*0a6a1f1dSLionel Sambuc     namespace C {
106*0a6a1f1dSLionel Sambuc       using namespace A;
107*0a6a1f1dSLionel Sambuc       using namespace B;
108*0a6a1f1dSLionel Sambuc       struct S s; // expected-error {{ambiguous}}
109*0a6a1f1dSLionel Sambuc     }
110*0a6a1f1dSLionel Sambuc     namespace D {
111*0a6a1f1dSLionel Sambuc       // FIXME: This is valid.
112*0a6a1f1dSLionel Sambuc       using A::S;
113*0a6a1f1dSLionel Sambuc       typedef struct S S; // expected-note {{here}}
114*0a6a1f1dSLionel Sambuc       struct S s; // expected-error {{refers to a typedef}}
115*0a6a1f1dSLionel Sambuc     }
116*0a6a1f1dSLionel Sambuc     namespace E {
117*0a6a1f1dSLionel Sambuc       // FIXME: The standard doesn't say whether this is valid.
118*0a6a1f1dSLionel Sambuc       typedef A::S S;
119*0a6a1f1dSLionel Sambuc       using A::S;
120*0a6a1f1dSLionel Sambuc       struct S s;
121*0a6a1f1dSLionel Sambuc     }
122*0a6a1f1dSLionel Sambuc     namespace F {
123*0a6a1f1dSLionel Sambuc       typedef A::S S; // expected-note {{here}}
124*0a6a1f1dSLionel Sambuc     }
125*0a6a1f1dSLionel Sambuc     // FIXME: The standard doesn't say what to do in these cases, but
126*0a6a1f1dSLionel Sambuc     // our behavior should not depend on the order of the using-directives.
127*0a6a1f1dSLionel Sambuc     namespace G {
128*0a6a1f1dSLionel Sambuc       using namespace A;
129*0a6a1f1dSLionel Sambuc       using namespace F;
130*0a6a1f1dSLionel Sambuc       struct S s;
131*0a6a1f1dSLionel Sambuc     }
132*0a6a1f1dSLionel Sambuc     namespace H {
133*0a6a1f1dSLionel Sambuc       using namespace F;
134*0a6a1f1dSLionel Sambuc       using namespace A;
135*0a6a1f1dSLionel Sambuc       struct S s; // expected-error {{refers to a typedef}}
136*0a6a1f1dSLionel Sambuc     }
137*0a6a1f1dSLionel Sambuc   }
138*0a6a1f1dSLionel Sambuc }
139f4a2713aSLionel Sambuc 
140f4a2713aSLionel Sambuc namespace dr408 { // dr408: 3.4
g()141f4a2713aSLionel Sambuc   template<int N> void g() { int arr[N != 1 ? 1 : -1]; }
g()142f4a2713aSLionel Sambuc   template<> void g<2>() { }
143f4a2713aSLionel Sambuc 
144f4a2713aSLionel Sambuc   template<typename T> struct S {
145f4a2713aSLionel Sambuc     static int i[];
146f4a2713aSLionel Sambuc     void f();
147f4a2713aSLionel Sambuc   };
148f4a2713aSLionel Sambuc   template<typename T> int S<T>::i[] = { 1 };
149f4a2713aSLionel Sambuc 
f()150f4a2713aSLionel Sambuc   template<typename T> void S<T>::f() {
151f4a2713aSLionel Sambuc     g<sizeof (i) / sizeof (int)>();
152f4a2713aSLionel Sambuc   }
153f4a2713aSLionel Sambuc   template<> int S<int>::i[] = { 1, 2 };
154f4a2713aSLionel Sambuc   template void S<int>::f(); // uses g<2>(), not g<1>().
155f4a2713aSLionel Sambuc 
156f4a2713aSLionel Sambuc 
157f4a2713aSLionel Sambuc   template<typename T> struct R {
158f4a2713aSLionel Sambuc     static int arr[];
159f4a2713aSLionel Sambuc     void f();
160f4a2713aSLionel Sambuc   };
161f4a2713aSLionel Sambuc   template<typename T> int R<T>::arr[1];
f()162f4a2713aSLionel Sambuc   template<typename T> void R<T>::f() {
163f4a2713aSLionel Sambuc     int arr[sizeof(arr) != sizeof(int) ? 1 : -1];
164f4a2713aSLionel Sambuc   }
165f4a2713aSLionel Sambuc   template<> int R<int>::arr[2];
166f4a2713aSLionel Sambuc   template void R<int>::f();
167f4a2713aSLionel Sambuc }
168*0a6a1f1dSLionel Sambuc 
169*0a6a1f1dSLionel Sambuc namespace dr409 { // dr409: yes
170*0a6a1f1dSLionel Sambuc   template<typename T> struct A {
171*0a6a1f1dSLionel Sambuc     typedef int B;
172*0a6a1f1dSLionel Sambuc     B b1;
173*0a6a1f1dSLionel Sambuc     A::B b2;
174*0a6a1f1dSLionel Sambuc     A<T>::B b3;
175*0a6a1f1dSLionel Sambuc     A<T*>::B b4; // expected-error {{missing 'typename'}}
176*0a6a1f1dSLionel Sambuc   };
177*0a6a1f1dSLionel Sambuc }
178*0a6a1f1dSLionel Sambuc 
179*0a6a1f1dSLionel Sambuc namespace dr410 { // dr410: no
180*0a6a1f1dSLionel Sambuc   template<class T> void f(T);
181*0a6a1f1dSLionel Sambuc   void g(int);
182*0a6a1f1dSLionel Sambuc   namespace M {
183*0a6a1f1dSLionel Sambuc     template<class T> void h(T);
184*0a6a1f1dSLionel Sambuc     template<class T> void i(T);
185*0a6a1f1dSLionel Sambuc     struct A {
186*0a6a1f1dSLionel Sambuc       friend void f<>(int);
187*0a6a1f1dSLionel Sambuc       friend void h<>(int);
188*0a6a1f1dSLionel Sambuc       friend void g(int);
189*0a6a1f1dSLionel Sambuc       template<class T> void i(T);
190*0a6a1f1dSLionel Sambuc       friend void i<>(int);
191*0a6a1f1dSLionel Sambuc     private:
192*0a6a1f1dSLionel Sambuc       static void z(); // expected-note {{private}}
193*0a6a1f1dSLionel Sambuc     };
194*0a6a1f1dSLionel Sambuc 
h(int)195*0a6a1f1dSLionel Sambuc     template<> void h(int) { A::z(); }
196*0a6a1f1dSLionel Sambuc     // FIXME: This should be ill-formed. The member A::i<> is befriended,
197*0a6a1f1dSLionel Sambuc     // not this function.
i(int)198*0a6a1f1dSLionel Sambuc     template<> void i(int) { A::z(); }
199*0a6a1f1dSLionel Sambuc   }
f(int)200*0a6a1f1dSLionel Sambuc   template<> void f(int) { M::A::z(); }
g(int)201*0a6a1f1dSLionel Sambuc   void g(int) { M::A::z(); } // expected-error {{private}}
202*0a6a1f1dSLionel Sambuc }
203*0a6a1f1dSLionel Sambuc 
204*0a6a1f1dSLionel Sambuc // dr412 is in its own file.
205*0a6a1f1dSLionel Sambuc 
206*0a6a1f1dSLionel Sambuc namespace dr413 { // dr413: yes
207*0a6a1f1dSLionel Sambuc   struct S {
208*0a6a1f1dSLionel Sambuc     int a;
209*0a6a1f1dSLionel Sambuc     int : 17;
210*0a6a1f1dSLionel Sambuc     int b;
211*0a6a1f1dSLionel Sambuc   };
212*0a6a1f1dSLionel Sambuc   S s = { 1, 2, 3 }; // expected-error {{excess elements}}
213*0a6a1f1dSLionel Sambuc 
214*0a6a1f1dSLionel Sambuc   struct E {};
215*0a6a1f1dSLionel Sambuc   struct T { // expected-note {{here}}
216*0a6a1f1dSLionel Sambuc     int a;
217*0a6a1f1dSLionel Sambuc     E e;
218*0a6a1f1dSLionel Sambuc     int b;
219*0a6a1f1dSLionel Sambuc   };
220*0a6a1f1dSLionel Sambuc   T t1 = { 1, {}, 2 };
221*0a6a1f1dSLionel Sambuc   T t2 = { 1, 2 }; // expected-error {{aggregate with no elements requires explicit braces}}
222*0a6a1f1dSLionel Sambuc }
223*0a6a1f1dSLionel Sambuc 
224*0a6a1f1dSLionel Sambuc namespace dr414 { // dr414: dup 305
225*0a6a1f1dSLionel Sambuc   struct X {};
f()226*0a6a1f1dSLionel Sambuc   void f() {
227*0a6a1f1dSLionel Sambuc     X x;
228*0a6a1f1dSLionel Sambuc     struct X {};
229*0a6a1f1dSLionel Sambuc     x.~X();
230*0a6a1f1dSLionel Sambuc   }
231*0a6a1f1dSLionel Sambuc }
232*0a6a1f1dSLionel Sambuc 
233*0a6a1f1dSLionel Sambuc namespace dr415 { // dr415: yes
f(T,...)234*0a6a1f1dSLionel Sambuc   template<typename T> void f(T, ...) { T::error; }
235*0a6a1f1dSLionel Sambuc   void f(int, int);
g()236*0a6a1f1dSLionel Sambuc   void g() { f(0, 0); } // ok
237*0a6a1f1dSLionel Sambuc }
238*0a6a1f1dSLionel Sambuc 
239*0a6a1f1dSLionel Sambuc namespace dr416 { // dr416: yes
240*0a6a1f1dSLionel Sambuc   extern struct A a;
241*0a6a1f1dSLionel Sambuc   int &operator+(const A&, const A&);
242*0a6a1f1dSLionel Sambuc   int &k = a + a;
243*0a6a1f1dSLionel Sambuc   struct A { float &operator+(A&); };
244*0a6a1f1dSLionel Sambuc   float &f = a + a;
245*0a6a1f1dSLionel Sambuc }
246*0a6a1f1dSLionel Sambuc 
247*0a6a1f1dSLionel Sambuc namespace dr417 { // dr417: no
248*0a6a1f1dSLionel Sambuc   struct A;
249*0a6a1f1dSLionel Sambuc   struct dr417::A {}; // expected-warning {{extra qualification}}
250*0a6a1f1dSLionel Sambuc   struct B { struct X; };
251*0a6a1f1dSLionel Sambuc   struct C : B {};
252*0a6a1f1dSLionel Sambuc   struct C::X {}; // expected-error {{no struct named 'X' in 'dr417::C'}}
253*0a6a1f1dSLionel Sambuc   struct B::X { struct Y; };
254*0a6a1f1dSLionel Sambuc   struct C::X::Y {}; // ok!
255*0a6a1f1dSLionel Sambuc   namespace N {
256*0a6a1f1dSLionel Sambuc     struct D;
257*0a6a1f1dSLionel Sambuc     struct E;
258*0a6a1f1dSLionel Sambuc     struct F;
259*0a6a1f1dSLionel Sambuc     struct H;
260*0a6a1f1dSLionel Sambuc   }
261*0a6a1f1dSLionel Sambuc   // FIXME: This is ill-formed.
262*0a6a1f1dSLionel Sambuc   using N::D;
263*0a6a1f1dSLionel Sambuc   struct dr417::D {}; // expected-warning {{extra qualification}}
264*0a6a1f1dSLionel Sambuc   using namespace N;
265*0a6a1f1dSLionel Sambuc   struct dr417::E {}; // expected-warning {{extra qualification}} expected-error {{no struct named 'E'}}
266*0a6a1f1dSLionel Sambuc   struct N::F {};
267*0a6a1f1dSLionel Sambuc   struct G;
268*0a6a1f1dSLionel Sambuc   using N::H;
269*0a6a1f1dSLionel Sambuc   namespace M {
270*0a6a1f1dSLionel Sambuc     struct dr417::G {}; // expected-error {{namespace 'M' does not enclose}}
271*0a6a1f1dSLionel Sambuc     struct dr417::H {}; // expected-error {{namespace 'M' does not enclose}}
272*0a6a1f1dSLionel Sambuc   }
273*0a6a1f1dSLionel Sambuc }
274*0a6a1f1dSLionel Sambuc 
275*0a6a1f1dSLionel Sambuc namespace dr420 { // dr420: yes
276*0a6a1f1dSLionel Sambuc   template<typename T> struct ptr {
277*0a6a1f1dSLionel Sambuc     T *operator->() const;
278*0a6a1f1dSLionel Sambuc     T &operator*() const;
279*0a6a1f1dSLionel Sambuc   };
test(P p)280*0a6a1f1dSLionel Sambuc   template<typename T, typename P> void test(P p) {
281*0a6a1f1dSLionel Sambuc     p->~T();
282*0a6a1f1dSLionel Sambuc     p->T::~T();
283*0a6a1f1dSLionel Sambuc     (*p).~T();
284*0a6a1f1dSLionel Sambuc     (*p).T::~T();
285*0a6a1f1dSLionel Sambuc   }
286*0a6a1f1dSLionel Sambuc   struct X {};
287*0a6a1f1dSLionel Sambuc   template void test<int>(int*);
288*0a6a1f1dSLionel Sambuc   template void test<int>(ptr<int>);
289*0a6a1f1dSLionel Sambuc   template void test<X>(X*);
290*0a6a1f1dSLionel Sambuc   template void test<X>(ptr<X>);
291*0a6a1f1dSLionel Sambuc 
292*0a6a1f1dSLionel Sambuc   template<typename T>
test2(T p)293*0a6a1f1dSLionel Sambuc   void test2(T p) {
294*0a6a1f1dSLionel Sambuc     p->template Y<int>::~Y<int>();
295*0a6a1f1dSLionel Sambuc     p->~Y<int>();
296*0a6a1f1dSLionel Sambuc     // FIXME: This is ill-formed, but this diagnostic is terrible. We should
297*0a6a1f1dSLionel Sambuc     // reject this in the parser.
298*0a6a1f1dSLionel Sambuc     p->template ~Y<int>(); // expected-error 2{{no member named '~typename Y<int>'}}
299*0a6a1f1dSLionel Sambuc   }
300*0a6a1f1dSLionel Sambuc   template<typename T> struct Y {};
301*0a6a1f1dSLionel Sambuc   template void test2(Y<int>*); // expected-note {{instantiation}}
302*0a6a1f1dSLionel Sambuc   template void test2(ptr<Y<int> >); // expected-note {{instantiation}}
303*0a6a1f1dSLionel Sambuc 
test3(int * p,ptr<int> q)304*0a6a1f1dSLionel Sambuc   void test3(int *p, ptr<int> q) {
305*0a6a1f1dSLionel Sambuc     typedef int Int;
306*0a6a1f1dSLionel Sambuc     p->~Int();
307*0a6a1f1dSLionel Sambuc     q->~Int();
308*0a6a1f1dSLionel Sambuc     p->Int::~Int();
309*0a6a1f1dSLionel Sambuc     q->Int::~Int();
310*0a6a1f1dSLionel Sambuc   }
311*0a6a1f1dSLionel Sambuc 
312*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
313*0a6a1f1dSLionel Sambuc   template<typename T> using id = T;
314*0a6a1f1dSLionel Sambuc   struct A { template<typename T> using id = T; };
test4(int * p,ptr<int> q)315*0a6a1f1dSLionel Sambuc   void test4(int *p, ptr<int> q) {
316*0a6a1f1dSLionel Sambuc     p->~id<int>();
317*0a6a1f1dSLionel Sambuc     q->~id<int>();
318*0a6a1f1dSLionel Sambuc     p->id<int>::~id<int>();
319*0a6a1f1dSLionel Sambuc     q->id<int>::~id<int>();
320*0a6a1f1dSLionel Sambuc     p->template id<int>::~id<int>(); // expected-error {{expected unqualified-id}}
321*0a6a1f1dSLionel Sambuc     q->template id<int>::~id<int>(); // expected-error {{expected unqualified-id}}
322*0a6a1f1dSLionel Sambuc     p->A::template id<int>::~id<int>();
323*0a6a1f1dSLionel Sambuc     q->A::template id<int>::~id<int>();
324*0a6a1f1dSLionel Sambuc   }
325*0a6a1f1dSLionel Sambuc #endif
326*0a6a1f1dSLionel Sambuc }
327*0a6a1f1dSLionel Sambuc 
328*0a6a1f1dSLionel Sambuc namespace dr421 { // dr421: yes
329*0a6a1f1dSLionel Sambuc   struct X { X(); int n; int &r; };
330*0a6a1f1dSLionel Sambuc   int *p = &X().n; // expected-error {{taking the address of a temporary}}
331*0a6a1f1dSLionel Sambuc   int *q = &X().r;
332*0a6a1f1dSLionel Sambuc }
333*0a6a1f1dSLionel Sambuc 
334*0a6a1f1dSLionel Sambuc namespace dr422 { // dr422: yes
f()335*0a6a1f1dSLionel Sambuc   template<typename T, typename U> void f() {
336*0a6a1f1dSLionel Sambuc     typedef T type; // expected-note {{prev}}
337*0a6a1f1dSLionel Sambuc     typedef U type; // expected-error {{redef}}
338*0a6a1f1dSLionel Sambuc   }
339*0a6a1f1dSLionel Sambuc   template void f<int, int>();
340*0a6a1f1dSLionel Sambuc   template void f<int, char>(); // expected-note {{instantiation}}
341*0a6a1f1dSLionel Sambuc }
342*0a6a1f1dSLionel Sambuc 
343*0a6a1f1dSLionel Sambuc namespace dr423 { // dr423: yes
344*0a6a1f1dSLionel Sambuc   template<typename T> struct X { operator T&(); };
f(X<int> x)345*0a6a1f1dSLionel Sambuc   void f(X<int> x) { x += 1; }
346*0a6a1f1dSLionel Sambuc }
347*0a6a1f1dSLionel Sambuc 
348*0a6a1f1dSLionel Sambuc namespace dr424 { // dr424: yes
349*0a6a1f1dSLionel Sambuc   struct A {
350*0a6a1f1dSLionel Sambuc     typedef int N; // expected-note {{previous}}
351*0a6a1f1dSLionel Sambuc     typedef int N; // expected-error {{redefinition}}
352*0a6a1f1dSLionel Sambuc 
353*0a6a1f1dSLionel Sambuc     struct X;
354*0a6a1f1dSLionel Sambuc     typedef X X; // expected-note {{previous}}
355*0a6a1f1dSLionel Sambuc     struct X {};
356*0a6a1f1dSLionel Sambuc 
357*0a6a1f1dSLionel Sambuc     struct X *p;
358*0a6a1f1dSLionel Sambuc     struct A::X *q;
359*0a6a1f1dSLionel Sambuc     X *r;
360*0a6a1f1dSLionel Sambuc 
361*0a6a1f1dSLionel Sambuc     typedef X X; // expected-error {{redefinition}}
362*0a6a1f1dSLionel Sambuc   };
363*0a6a1f1dSLionel Sambuc   struct B {
364*0a6a1f1dSLionel Sambuc     typedef int N;
365*0a6a1f1dSLionel Sambuc   };
366*0a6a1f1dSLionel Sambuc   struct C : B {
367*0a6a1f1dSLionel Sambuc     typedef int N; // expected-note {{previous}}
368*0a6a1f1dSLionel Sambuc     typedef int N; // expected-error {{redefinition}}
369*0a6a1f1dSLionel Sambuc   };
370*0a6a1f1dSLionel Sambuc }
371*0a6a1f1dSLionel Sambuc 
372*0a6a1f1dSLionel Sambuc namespace dr425 { // dr425: yes
373*0a6a1f1dSLionel Sambuc   struct A { template<typename T> operator T() const; } a;
374*0a6a1f1dSLionel Sambuc   float f = 1.0f * a; // expected-error {{ambiguous}} expected-note 5+{{built-in candidate}}
375*0a6a1f1dSLionel Sambuc 
376*0a6a1f1dSLionel Sambuc   template<typename T> struct is_float;
377*0a6a1f1dSLionel Sambuc   template<> struct is_float<float> { typedef void type; };
378*0a6a1f1dSLionel Sambuc 
379*0a6a1f1dSLionel Sambuc   struct B {
380*0a6a1f1dSLionel Sambuc     template<typename T, typename U = typename is_float<T>::type> operator T() const; // expected-error 0-1{{extension}}
381*0a6a1f1dSLionel Sambuc   } b;
382*0a6a1f1dSLionel Sambuc   float g = 1.0f * b; // ok
383*0a6a1f1dSLionel Sambuc }
384*0a6a1f1dSLionel Sambuc 
385*0a6a1f1dSLionel Sambuc namespace dr427 { // dr427: yes
386*0a6a1f1dSLionel Sambuc   struct B {};
387*0a6a1f1dSLionel Sambuc   struct D : public B {
388*0a6a1f1dSLionel Sambuc     D(B &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
389*0a6a1f1dSLionel Sambuc   };
390*0a6a1f1dSLionel Sambuc 
391*0a6a1f1dSLionel Sambuc   extern D d1;
392*0a6a1f1dSLionel Sambuc   B &b = d1;
393*0a6a1f1dSLionel Sambuc   const D &d2 = static_cast<const D&>(b);
394*0a6a1f1dSLionel Sambuc   const D &d3 = (const D&)b;
395*0a6a1f1dSLionel Sambuc   const D &d4(b); // expected-error {{deleted}}
396*0a6a1f1dSLionel Sambuc }
397*0a6a1f1dSLionel Sambuc 
398*0a6a1f1dSLionel Sambuc namespace dr428 { // dr428: yes
399*0a6a1f1dSLionel Sambuc   template<typename T> T make();
400*0a6a1f1dSLionel Sambuc   extern struct X x; // expected-note 5{{forward declaration}}
f()401*0a6a1f1dSLionel Sambuc   void f() {
402*0a6a1f1dSLionel Sambuc     throw void(); // expected-error {{cannot throw}}
403*0a6a1f1dSLionel Sambuc     throw make<void*>();
404*0a6a1f1dSLionel Sambuc     throw make<const volatile void*>();
405*0a6a1f1dSLionel Sambuc     throw x; // expected-error {{cannot throw}}
406*0a6a1f1dSLionel Sambuc     throw make<X&>(); // expected-error {{cannot throw}}
407*0a6a1f1dSLionel Sambuc     throw make<X*>(); // expected-error {{cannot throw}}
408*0a6a1f1dSLionel Sambuc     throw make<const volatile X&>(); // expected-error {{cannot throw}}
409*0a6a1f1dSLionel Sambuc     throw make<const volatile X*>(); // expected-error {{cannot throw}}
410*0a6a1f1dSLionel Sambuc   }
411*0a6a1f1dSLionel Sambuc }
412*0a6a1f1dSLionel Sambuc 
413*0a6a1f1dSLionel Sambuc namespace dr429 { // dr429: yes c++11
414*0a6a1f1dSLionel Sambuc   // FIXME: This rule is obviously intended to apply to C++98 as well.
415*0a6a1f1dSLionel Sambuc   struct A {
416*0a6a1f1dSLionel Sambuc     static void *operator new(size_t, size_t);
417*0a6a1f1dSLionel Sambuc     static void operator delete(void*, size_t);
418*0a6a1f1dSLionel Sambuc   } *a = new (0) A;
419*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
420*0a6a1f1dSLionel Sambuc   // expected-error@-2 {{'new' expression with placement arguments refers to non-placement 'operator delete'}}
421*0a6a1f1dSLionel Sambuc   // expected-note@-4 {{here}}
422*0a6a1f1dSLionel Sambuc #endif
423*0a6a1f1dSLionel Sambuc   struct B {
424*0a6a1f1dSLionel Sambuc     static void *operator new(size_t, size_t);
425*0a6a1f1dSLionel Sambuc     static void operator delete(void*);
426*0a6a1f1dSLionel Sambuc     static void operator delete(void*, size_t);
427*0a6a1f1dSLionel Sambuc   } *b = new (0) B; // ok, second delete is not a non-placement deallocation function
428*0a6a1f1dSLionel Sambuc }
429*0a6a1f1dSLionel Sambuc 
430*0a6a1f1dSLionel Sambuc namespace dr430 { // dr430: yes c++11
431*0a6a1f1dSLionel Sambuc   // resolved by n2239
432*0a6a1f1dSLionel Sambuc   // FIXME: This should apply in C++98 too.
f(int n)433*0a6a1f1dSLionel Sambuc   void f(int n) {
434*0a6a1f1dSLionel Sambuc     int a[] = { n++, n++, n++ };
435*0a6a1f1dSLionel Sambuc #if __cplusplus < 201103L
436*0a6a1f1dSLionel Sambuc     // expected-warning@-2 {{multiple unsequenced modifications to 'n'}}
437*0a6a1f1dSLionel Sambuc #endif
438*0a6a1f1dSLionel Sambuc   }
439*0a6a1f1dSLionel Sambuc }
440*0a6a1f1dSLionel Sambuc 
441*0a6a1f1dSLionel Sambuc namespace dr431 { // dr431: yes
442*0a6a1f1dSLionel Sambuc   struct A {
443*0a6a1f1dSLionel Sambuc     template<typename T> T *get();
444*0a6a1f1dSLionel Sambuc     template<typename T> struct B {
445*0a6a1f1dSLionel Sambuc       template<typename U> U *get();
446*0a6a1f1dSLionel Sambuc     };
447*0a6a1f1dSLionel Sambuc   };
448*0a6a1f1dSLionel Sambuc 
f(A a)449*0a6a1f1dSLionel Sambuc   template<typename T> void f(A a) {
450*0a6a1f1dSLionel Sambuc     a.get<A>()->get<T>();
451*0a6a1f1dSLionel Sambuc     a.get<T>()
452*0a6a1f1dSLionel Sambuc         ->get<T>(); // expected-error {{use 'template'}}
453*0a6a1f1dSLionel Sambuc     a.get<T>()->template get<T>();
454*0a6a1f1dSLionel Sambuc     a.A::get<T>();
455*0a6a1f1dSLionel Sambuc     A::B<int> *b = a.get<A::B<int> >();
456*0a6a1f1dSLionel Sambuc     b->get<int>();
457*0a6a1f1dSLionel Sambuc     b->A::B<int>::get<int>();
458*0a6a1f1dSLionel Sambuc     b->A::B<int>::get<T>();
459*0a6a1f1dSLionel Sambuc     b->A::B<T>::get<int>(); // expected-error {{use 'template'}}
460*0a6a1f1dSLionel Sambuc     b->A::B<T>::template get<int>();
461*0a6a1f1dSLionel Sambuc     b->A::B<T>::get<T>(); // expected-error {{use 'template'}}
462*0a6a1f1dSLionel Sambuc     b->A::B<T>::template get<T>();
463*0a6a1f1dSLionel Sambuc     A::B<T> *c = a.get<A::B<T> >();
464*0a6a1f1dSLionel Sambuc     c->get<int>(); // expected-error {{use 'template'}}
465*0a6a1f1dSLionel Sambuc     c->template get<int>();
466*0a6a1f1dSLionel Sambuc   }
467*0a6a1f1dSLionel Sambuc }
468*0a6a1f1dSLionel Sambuc 
469*0a6a1f1dSLionel Sambuc namespace dr432 { // dr432: yes
470*0a6a1f1dSLionel Sambuc   template<typename T> struct A {};
471*0a6a1f1dSLionel Sambuc   template<typename T> struct B : A<B> {}; // expected-error {{requires template arguments}} expected-note {{declared}}
472*0a6a1f1dSLionel Sambuc   template<typename T> struct C : A<C<T> > {};
473*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
474*0a6a1f1dSLionel Sambuc   template<typename T> struct D : decltype(A<D>()) {}; // expected-error {{requires template arguments}} expected-note {{declared}}
475*0a6a1f1dSLionel Sambuc #endif
476*0a6a1f1dSLionel Sambuc }
477*0a6a1f1dSLionel Sambuc 
478*0a6a1f1dSLionel Sambuc namespace dr433 { // dr433: yes
479*0a6a1f1dSLionel Sambuc   template<class T> struct S {
480*0a6a1f1dSLionel Sambuc     void f(union U*);
481*0a6a1f1dSLionel Sambuc   };
482*0a6a1f1dSLionel Sambuc   U *p;
f(union U *)483*0a6a1f1dSLionel Sambuc   template<class T> void S<T>::f(union U*) {}
484*0a6a1f1dSLionel Sambuc 
485*0a6a1f1dSLionel Sambuc   S<int> s;
486*0a6a1f1dSLionel Sambuc }
487*0a6a1f1dSLionel Sambuc 
488*0a6a1f1dSLionel Sambuc namespace dr434 { // dr434: yes
f()489*0a6a1f1dSLionel Sambuc   void f() {
490*0a6a1f1dSLionel Sambuc     const int ci = 0;
491*0a6a1f1dSLionel Sambuc     int *pi = 0;
492*0a6a1f1dSLionel Sambuc     const int *&rpci = pi; // expected-error {{cannot bind}}
493*0a6a1f1dSLionel Sambuc     rpci = &ci;
494*0a6a1f1dSLionel Sambuc     *pi = 1;
495*0a6a1f1dSLionel Sambuc   }
496*0a6a1f1dSLionel Sambuc }
497*0a6a1f1dSLionel Sambuc 
498*0a6a1f1dSLionel Sambuc // dr435: na
499*0a6a1f1dSLionel Sambuc 
500*0a6a1f1dSLionel Sambuc namespace dr436 { // dr436: yes
501*0a6a1f1dSLionel Sambuc   enum E { f }; // expected-note {{previous}}
502*0a6a1f1dSLionel Sambuc   void f(); // expected-error {{redefinition}}
503*0a6a1f1dSLionel Sambuc }
504*0a6a1f1dSLionel Sambuc 
505*0a6a1f1dSLionel Sambuc namespace dr437 { // dr437: sup 1308
506*0a6a1f1dSLionel Sambuc   // This is superseded by 1308, which is in turn superseded by 1330,
507*0a6a1f1dSLionel Sambuc   // which restores this rule.
508*0a6a1f1dSLionel Sambuc   template<typename U> struct T : U {};
509*0a6a1f1dSLionel Sambuc   struct S {
510*0a6a1f1dSLionel Sambuc     void f() throw(S);
511*0a6a1f1dSLionel Sambuc     void g() throw(T<S>);
512*0a6a1f1dSLionel Sambuc     struct U;
513*0a6a1f1dSLionel Sambuc     void h() throw(U);
514*0a6a1f1dSLionel Sambuc     struct U {};
515*0a6a1f1dSLionel Sambuc   };
516*0a6a1f1dSLionel Sambuc }
517*0a6a1f1dSLionel Sambuc 
518*0a6a1f1dSLionel Sambuc // dr438 FIXME write a codegen test
519*0a6a1f1dSLionel Sambuc // dr439 FIXME write a codegen test
520*0a6a1f1dSLionel Sambuc // dr441 FIXME write a codegen test
521*0a6a1f1dSLionel Sambuc // dr442: sup 348
522*0a6a1f1dSLionel Sambuc // dr443: na
523*0a6a1f1dSLionel Sambuc 
524*0a6a1f1dSLionel Sambuc namespace dr444 { // dr444: yes
525*0a6a1f1dSLionel Sambuc   struct D;
526*0a6a1f1dSLionel Sambuc   struct B { // expected-note {{candidate is the implicit copy}} expected-note 0-1 {{implicit move}}
527*0a6a1f1dSLionel Sambuc     D &operator=(D &) = delete; // expected-error 0-1{{extension}} expected-note {{deleted}}
528*0a6a1f1dSLionel Sambuc   };
529*0a6a1f1dSLionel Sambuc   struct D : B { // expected-note {{candidate is the implicit}} expected-note 0-1 {{implicit move}}
530*0a6a1f1dSLionel Sambuc     using B::operator=;
531*0a6a1f1dSLionel Sambuc   } extern d;
f()532*0a6a1f1dSLionel Sambuc   void f() {
533*0a6a1f1dSLionel Sambuc     d = d; // expected-error {{deleted}}
534*0a6a1f1dSLionel Sambuc   }
535*0a6a1f1dSLionel Sambuc }
536*0a6a1f1dSLionel Sambuc 
537*0a6a1f1dSLionel Sambuc namespace dr445 { // dr445: yes
538*0a6a1f1dSLionel Sambuc   class A { void f(); }; // expected-note {{private}}
539*0a6a1f1dSLionel Sambuc   struct B {
540*0a6a1f1dSLionel Sambuc     friend void A::f(); // expected-error {{private}}
541*0a6a1f1dSLionel Sambuc   };
542*0a6a1f1dSLionel Sambuc }
543*0a6a1f1dSLionel Sambuc 
544*0a6a1f1dSLionel Sambuc namespace dr446 { // dr446: yes
545*0a6a1f1dSLionel Sambuc   struct C;
546*0a6a1f1dSLionel Sambuc   struct A {
547*0a6a1f1dSLionel Sambuc     A();
548*0a6a1f1dSLionel Sambuc     A(const A&) = delete; // expected-error 0-1{{extension}} expected-note +{{deleted}}
549*0a6a1f1dSLionel Sambuc     A(const C&);
550*0a6a1f1dSLionel Sambuc   };
551*0a6a1f1dSLionel Sambuc   struct C : A {};
f(A a,bool b,C c)552*0a6a1f1dSLionel Sambuc   void f(A a, bool b, C c) {
553*0a6a1f1dSLionel Sambuc     void(b ? a : a);
554*0a6a1f1dSLionel Sambuc     b ? A() : a; // expected-error {{deleted}}
555*0a6a1f1dSLionel Sambuc     b ? a : A(); // expected-error {{deleted}}
556*0a6a1f1dSLionel Sambuc     b ? A() : A(); // expected-error {{deleted}}
557*0a6a1f1dSLionel Sambuc 
558*0a6a1f1dSLionel Sambuc     void(b ? a : c);
559*0a6a1f1dSLionel Sambuc     b ? a : C(); // expected-error {{deleted}}
560*0a6a1f1dSLionel Sambuc     b ? c : A(); // expected-error {{deleted}}
561*0a6a1f1dSLionel Sambuc     b ? A() : C(); // expected-error {{deleted}}
562*0a6a1f1dSLionel Sambuc   }
563*0a6a1f1dSLionel Sambuc }
564*0a6a1f1dSLionel Sambuc 
565*0a6a1f1dSLionel Sambuc namespace dr447 { // dr447: yes
566*0a6a1f1dSLionel Sambuc   struct A { int n; int a[4]; };
567*0a6a1f1dSLionel Sambuc   template<int> struct U {
568*0a6a1f1dSLionel Sambuc     typedef int type;
569*0a6a1f1dSLionel Sambuc     template<typename V> static void h();
570*0a6a1f1dSLionel Sambuc   };
571*0a6a1f1dSLionel Sambuc   template<typename T> U<sizeof(T)> g(T);
f(int n)572*0a6a1f1dSLionel Sambuc   template<typename T, int N> void f(int n) {
573*0a6a1f1dSLionel Sambuc     // ok, not type dependent
574*0a6a1f1dSLionel Sambuc     g(__builtin_offsetof(A, n)).h<int>();
575*0a6a1f1dSLionel Sambuc     g(__builtin_offsetof(T, n)).h<int>();
576*0a6a1f1dSLionel Sambuc     // value dependent if first argument is a dependent type
577*0a6a1f1dSLionel Sambuc     U<__builtin_offsetof(A, n)>::type a;
578*0a6a1f1dSLionel Sambuc     U<__builtin_offsetof(T, n)>::type b; // expected-error +{{}} expected-warning 0+{{}}
579*0a6a1f1dSLionel Sambuc     // as an extension, we allow the member-designator to include array indices
580*0a6a1f1dSLionel Sambuc     g(__builtin_offsetof(A, a[0])).h<int>(); // expected-error {{extension}}
581*0a6a1f1dSLionel Sambuc     g(__builtin_offsetof(A, a[N])).h<int>(); // expected-error {{extension}}
582*0a6a1f1dSLionel Sambuc     U<__builtin_offsetof(A, a[0])>::type c; // expected-error {{extension}}
583*0a6a1f1dSLionel Sambuc     U<__builtin_offsetof(A, a[N])>::type d; // expected-error {{extension}} expected-error +{{}} expected-warning 0+{{}}
584*0a6a1f1dSLionel Sambuc   }
585*0a6a1f1dSLionel Sambuc }
586*0a6a1f1dSLionel Sambuc 
587*0a6a1f1dSLionel Sambuc namespace dr448 { // dr448: yes
588*0a6a1f1dSLionel Sambuc   template<typename T = int> void f(int); // expected-error 0-1{{extension}} expected-note {{no known conversion}}
g(T t)589*0a6a1f1dSLionel Sambuc   template<typename T> void g(T t) {
590*0a6a1f1dSLionel Sambuc     f<T>(t); // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
591*0a6a1f1dSLionel Sambuc     dr448::f(t); // expected-error {{no matching function}}
592*0a6a1f1dSLionel Sambuc   }
593*0a6a1f1dSLionel Sambuc   template<typename T> void f(T); // expected-note {{should be declared prior to the call site}}
594*0a6a1f1dSLionel Sambuc   namespace HideFromADL { struct X {}; }
595*0a6a1f1dSLionel Sambuc   template void g(int); // ok
596*0a6a1f1dSLionel Sambuc   template void g(HideFromADL::X); // expected-note {{instantiation of}}
597*0a6a1f1dSLionel Sambuc }
598*0a6a1f1dSLionel Sambuc 
599*0a6a1f1dSLionel Sambuc // dr449: na
600*0a6a1f1dSLionel Sambuc 
601*0a6a1f1dSLionel Sambuc namespace dr450 { // dr450: yes
602*0a6a1f1dSLionel Sambuc   typedef int A[3];
603*0a6a1f1dSLionel Sambuc   void f1(const A &);
604*0a6a1f1dSLionel Sambuc   void f2(A &); // expected-note +{{not viable}}
605*0a6a1f1dSLionel Sambuc   struct S { A n; };
g()606*0a6a1f1dSLionel Sambuc   void g() {
607*0a6a1f1dSLionel Sambuc     f1(S().n);
608*0a6a1f1dSLionel Sambuc     f2(S().n); // expected-error {{no match}}}
609*0a6a1f1dSLionel Sambuc   }
610*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
h()611*0a6a1f1dSLionel Sambuc   void h() {
612*0a6a1f1dSLionel Sambuc     f1(A{});
613*0a6a1f1dSLionel Sambuc     f2(A{}); // expected-error {{no match}}
614*0a6a1f1dSLionel Sambuc   }
615*0a6a1f1dSLionel Sambuc #endif
616*0a6a1f1dSLionel Sambuc }
617*0a6a1f1dSLionel Sambuc 
618*0a6a1f1dSLionel Sambuc namespace dr451 { // dr451: yes
619*0a6a1f1dSLionel Sambuc   const int a = 1 / 0; // expected-warning {{undefined}}
620*0a6a1f1dSLionel Sambuc   const int b = 1 / 0; // expected-warning {{undefined}}
621*0a6a1f1dSLionel Sambuc   int arr[b]; // expected-error +{{variable length arr}}
622*0a6a1f1dSLionel Sambuc }
623*0a6a1f1dSLionel Sambuc 
624*0a6a1f1dSLionel Sambuc namespace dr452 { // dr452: yes
625*0a6a1f1dSLionel Sambuc   struct A {
626*0a6a1f1dSLionel Sambuc     int a, b, c;
627*0a6a1f1dSLionel Sambuc     A *p;
628*0a6a1f1dSLionel Sambuc     int f();
Adr452::A629*0a6a1f1dSLionel Sambuc     A() : a(f()), b(this->f() + a), c(this->a), p(this) {}
630*0a6a1f1dSLionel Sambuc   };
631*0a6a1f1dSLionel Sambuc }
632*0a6a1f1dSLionel Sambuc 
633*0a6a1f1dSLionel Sambuc // dr454 FIXME write a codegen test
634*0a6a1f1dSLionel Sambuc 
635*0a6a1f1dSLionel Sambuc namespace dr456 { // dr456: yes
636*0a6a1f1dSLionel Sambuc   // sup 903 c++11
637*0a6a1f1dSLionel Sambuc   const int null = 0;
638*0a6a1f1dSLionel Sambuc   void *p = null;
639*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
640*0a6a1f1dSLionel Sambuc   // expected-error@-2 {{cannot initialize}}
641*0a6a1f1dSLionel Sambuc #else
642*0a6a1f1dSLionel Sambuc   // expected-warning@-4 {{null}}
643*0a6a1f1dSLionel Sambuc #endif
644*0a6a1f1dSLionel Sambuc 
645*0a6a1f1dSLionel Sambuc   const bool f = false;
646*0a6a1f1dSLionel Sambuc   void *q = f;
647*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
648*0a6a1f1dSLionel Sambuc   // expected-error@-2 {{cannot initialize}}
649*0a6a1f1dSLionel Sambuc #else
650*0a6a1f1dSLionel Sambuc   // expected-warning@-4 {{null}}
651*0a6a1f1dSLionel Sambuc #endif
652*0a6a1f1dSLionel Sambuc }
653*0a6a1f1dSLionel Sambuc 
654*0a6a1f1dSLionel Sambuc namespace dr457 { // dr457: yes
655*0a6a1f1dSLionel Sambuc   const int a = 1;
656*0a6a1f1dSLionel Sambuc   const volatile int b = 1;
657*0a6a1f1dSLionel Sambuc   int ax[a];
658*0a6a1f1dSLionel Sambuc   int bx[b]; // expected-error +{{variable length array}}
659*0a6a1f1dSLionel Sambuc 
660*0a6a1f1dSLionel Sambuc   enum E {
661*0a6a1f1dSLionel Sambuc     ea = a,
662*0a6a1f1dSLionel Sambuc     eb = b // expected-error {{not an integral constant}} expected-note {{read of volatile-qualified}}
663*0a6a1f1dSLionel Sambuc   };
664*0a6a1f1dSLionel Sambuc }
665*0a6a1f1dSLionel Sambuc 
666*0a6a1f1dSLionel Sambuc namespace dr458 { // dr458: no
667*0a6a1f1dSLionel Sambuc   struct A {
668*0a6a1f1dSLionel Sambuc     int T;
669*0a6a1f1dSLionel Sambuc     int f();
670*0a6a1f1dSLionel Sambuc     template<typename> int g();
671*0a6a1f1dSLionel Sambuc   };
672*0a6a1f1dSLionel Sambuc 
673*0a6a1f1dSLionel Sambuc   template<typename> struct B : A {
674*0a6a1f1dSLionel Sambuc     int f();
675*0a6a1f1dSLionel Sambuc     template<typename> int g();
676*0a6a1f1dSLionel Sambuc     template<typename> int h();
677*0a6a1f1dSLionel Sambuc   };
678*0a6a1f1dSLionel Sambuc 
f()679*0a6a1f1dSLionel Sambuc   int A::f() {
680*0a6a1f1dSLionel Sambuc     return T;
681*0a6a1f1dSLionel Sambuc   }
682*0a6a1f1dSLionel Sambuc   template<typename T>
g()683*0a6a1f1dSLionel Sambuc   int A::g() {
684*0a6a1f1dSLionel Sambuc     return T; // FIXME: this is invalid, it finds the template parameter
685*0a6a1f1dSLionel Sambuc   }
686*0a6a1f1dSLionel Sambuc 
687*0a6a1f1dSLionel Sambuc   template<typename T>
f()688*0a6a1f1dSLionel Sambuc   int B<T>::f() {
689*0a6a1f1dSLionel Sambuc     return T;
690*0a6a1f1dSLionel Sambuc   }
691*0a6a1f1dSLionel Sambuc   template<typename T> template<typename U>
g()692*0a6a1f1dSLionel Sambuc   int B<T>::g() {
693*0a6a1f1dSLionel Sambuc     return T;
694*0a6a1f1dSLionel Sambuc   }
695*0a6a1f1dSLionel Sambuc   template<typename U> template<typename T>
h()696*0a6a1f1dSLionel Sambuc   int B<U>::h() {
697*0a6a1f1dSLionel Sambuc     return T; // FIXME: this is invalid, it finds the template parameter
698*0a6a1f1dSLionel Sambuc   }
699*0a6a1f1dSLionel Sambuc }
700*0a6a1f1dSLionel Sambuc 
701*0a6a1f1dSLionel Sambuc namespace dr460 { // dr460: yes
702*0a6a1f1dSLionel Sambuc   namespace X { namespace Q { int n; } }
703*0a6a1f1dSLionel Sambuc   namespace Y {
704*0a6a1f1dSLionel Sambuc     using X; // expected-error {{requires a qualified name}}
705*0a6a1f1dSLionel Sambuc     using dr460::X; // expected-error {{cannot refer to namespace}}
706*0a6a1f1dSLionel Sambuc     using X::Q; // expected-error {{cannot refer to namespace}}
707*0a6a1f1dSLionel Sambuc   }
708*0a6a1f1dSLionel Sambuc }
709*0a6a1f1dSLionel Sambuc 
710*0a6a1f1dSLionel Sambuc // dr461: na
711*0a6a1f1dSLionel Sambuc // dr462 FIXME write a codegen test
712*0a6a1f1dSLionel Sambuc // dr463: na
713*0a6a1f1dSLionel Sambuc // dr464: na
714*0a6a1f1dSLionel Sambuc // dr465: na
715*0a6a1f1dSLionel Sambuc 
716*0a6a1f1dSLionel Sambuc namespace dr466 { // dr466: no
717*0a6a1f1dSLionel Sambuc   typedef int I;
718*0a6a1f1dSLionel Sambuc   typedef const int CI;
719*0a6a1f1dSLionel Sambuc   typedef volatile int VI;
f(int * a,CI * b,VI * c)720*0a6a1f1dSLionel Sambuc   void f(int *a, CI *b, VI *c) {
721*0a6a1f1dSLionel Sambuc     a->~I();
722*0a6a1f1dSLionel Sambuc     a->~CI();
723*0a6a1f1dSLionel Sambuc     a->~VI();
724*0a6a1f1dSLionel Sambuc     a->I::~I();
725*0a6a1f1dSLionel Sambuc     a->CI::~CI();
726*0a6a1f1dSLionel Sambuc     a->VI::~VI();
727*0a6a1f1dSLionel Sambuc 
728*0a6a1f1dSLionel Sambuc     a->CI::~VI(); // FIXME: This is invalid; CI and VI are not the same scalar type.
729*0a6a1f1dSLionel Sambuc 
730*0a6a1f1dSLionel Sambuc     b->~I();
731*0a6a1f1dSLionel Sambuc     b->~CI();
732*0a6a1f1dSLionel Sambuc     b->~VI();
733*0a6a1f1dSLionel Sambuc     b->I::~I();
734*0a6a1f1dSLionel Sambuc     b->CI::~CI();
735*0a6a1f1dSLionel Sambuc     b->VI::~VI();
736*0a6a1f1dSLionel Sambuc 
737*0a6a1f1dSLionel Sambuc     c->~I();
738*0a6a1f1dSLionel Sambuc     c->~CI();
739*0a6a1f1dSLionel Sambuc     c->~VI();
740*0a6a1f1dSLionel Sambuc     c->I::~I();
741*0a6a1f1dSLionel Sambuc     c->CI::~CI();
742*0a6a1f1dSLionel Sambuc     c->VI::~VI();
743*0a6a1f1dSLionel Sambuc   }
744*0a6a1f1dSLionel Sambuc }
745*0a6a1f1dSLionel Sambuc 
746*0a6a1f1dSLionel Sambuc namespace dr467 { // dr467: yes
747*0a6a1f1dSLionel Sambuc   int stuff();
748*0a6a1f1dSLionel Sambuc 
f()749*0a6a1f1dSLionel Sambuc   int f() {
750*0a6a1f1dSLionel Sambuc     static bool done;
751*0a6a1f1dSLionel Sambuc     if (done)
752*0a6a1f1dSLionel Sambuc       goto later;
753*0a6a1f1dSLionel Sambuc     static int k = stuff();
754*0a6a1f1dSLionel Sambuc     done = true;
755*0a6a1f1dSLionel Sambuc   later:
756*0a6a1f1dSLionel Sambuc     return k;
757*0a6a1f1dSLionel Sambuc   }
g()758*0a6a1f1dSLionel Sambuc   int g() {
759*0a6a1f1dSLionel Sambuc     goto later; // expected-error {{cannot jump}}
760*0a6a1f1dSLionel Sambuc     int k = stuff(); // expected-note {{bypasses variable initialization}}
761*0a6a1f1dSLionel Sambuc   later:
762*0a6a1f1dSLionel Sambuc     return k;
763*0a6a1f1dSLionel Sambuc   }
764*0a6a1f1dSLionel Sambuc }
765*0a6a1f1dSLionel Sambuc 
766*0a6a1f1dSLionel Sambuc namespace dr468 { // dr468: yes c++11
767*0a6a1f1dSLionel Sambuc   // FIXME: Should we allow this in C++98 too?
768*0a6a1f1dSLionel Sambuc   template<typename> struct A {
769*0a6a1f1dSLionel Sambuc     template<typename> struct B {
770*0a6a1f1dSLionel Sambuc       static int C;
771*0a6a1f1dSLionel Sambuc     };
772*0a6a1f1dSLionel Sambuc   };
773*0a6a1f1dSLionel Sambuc   int k = dr468::template A<int>::template B<char>::C;
774*0a6a1f1dSLionel Sambuc #if __cplusplus < 201103L
775*0a6a1f1dSLionel Sambuc   // expected-error@-2 2{{'template' keyword outside of a template}}
776*0a6a1f1dSLionel Sambuc #endif
777*0a6a1f1dSLionel Sambuc }
778*0a6a1f1dSLionel Sambuc 
779*0a6a1f1dSLionel Sambuc namespace dr469 { // dr469: no
780*0a6a1f1dSLionel Sambuc   // FIXME: The core issue here didn't really answer the question. We don't
781*0a6a1f1dSLionel Sambuc   // deduce 'const T' from a function or reference type in a class template...
782*0a6a1f1dSLionel Sambuc   template<typename T> struct X; // expected-note 2{{here}}
783*0a6a1f1dSLionel Sambuc   template<typename T> struct X<const T> {};
784*0a6a1f1dSLionel Sambuc   X<int&> x; // expected-error {{undefined}}
785*0a6a1f1dSLionel Sambuc   X<int()> y; // expected-error {{undefined}}
786*0a6a1f1dSLionel Sambuc 
787*0a6a1f1dSLionel Sambuc   // ... but we do in a function template. GCC and EDG fail deduction of 'f'
788*0a6a1f1dSLionel Sambuc   // and the second 'h'.
789*0a6a1f1dSLionel Sambuc   template<typename T> void f(const T *);
790*0a6a1f1dSLionel Sambuc   template<typename T> void g(T *, const T * = 0);
h(T *)791*0a6a1f1dSLionel Sambuc   template<typename T> void h(T *) { T::error; }
792*0a6a1f1dSLionel Sambuc   template<typename T> void h(const T *);
i()793*0a6a1f1dSLionel Sambuc   void i() {
794*0a6a1f1dSLionel Sambuc     f(&i);
795*0a6a1f1dSLionel Sambuc     g(&i);
796*0a6a1f1dSLionel Sambuc     h(&i);
797*0a6a1f1dSLionel Sambuc   }
798*0a6a1f1dSLionel Sambuc }
799*0a6a1f1dSLionel Sambuc 
800*0a6a1f1dSLionel Sambuc namespace dr470 { // dr470: yes
801*0a6a1f1dSLionel Sambuc   template<typename T> struct A {
802*0a6a1f1dSLionel Sambuc     struct B {};
803*0a6a1f1dSLionel Sambuc   };
804*0a6a1f1dSLionel Sambuc   template<typename T> struct C {
805*0a6a1f1dSLionel Sambuc   };
806*0a6a1f1dSLionel Sambuc 
807*0a6a1f1dSLionel Sambuc   template struct A<int>; // expected-note {{previous}}
808*0a6a1f1dSLionel Sambuc   template struct A<int>::B; // expected-error {{duplicate explicit instantiation}}
809*0a6a1f1dSLionel Sambuc 
810*0a6a1f1dSLionel Sambuc   // ok, instantiating C<char> doesn't instantiate base class members.
811*0a6a1f1dSLionel Sambuc   template struct A<char>;
812*0a6a1f1dSLionel Sambuc   template struct C<char>;
813*0a6a1f1dSLionel Sambuc }
814*0a6a1f1dSLionel Sambuc 
815*0a6a1f1dSLionel Sambuc namespace dr471 { // dr471: yes
816*0a6a1f1dSLionel Sambuc   struct A { int n; };
817*0a6a1f1dSLionel Sambuc   struct B : private virtual A {};
818*0a6a1f1dSLionel Sambuc   struct C : protected virtual A {};
fdr471::D819*0a6a1f1dSLionel Sambuc   struct D : B, C { int f() { return n; } };
820*0a6a1f1dSLionel Sambuc   struct E : private virtual A {
821*0a6a1f1dSLionel Sambuc     using A::n;
822*0a6a1f1dSLionel Sambuc   };
fdr471::F823*0a6a1f1dSLionel Sambuc   struct F : E, B { int f() { return n; } };
824*0a6a1f1dSLionel Sambuc   struct G : virtual A {
825*0a6a1f1dSLionel Sambuc   private:
826*0a6a1f1dSLionel Sambuc     using A::n; // expected-note {{here}}
827*0a6a1f1dSLionel Sambuc   };
fdr471::H828*0a6a1f1dSLionel Sambuc   struct H : B, G { int f() { return n; } }; // expected-error {{private}}
829*0a6a1f1dSLionel Sambuc }
830*0a6a1f1dSLionel Sambuc 
831*0a6a1f1dSLionel Sambuc namespace dr474 { // dr474: yes
832*0a6a1f1dSLionel Sambuc   namespace N {
833*0a6a1f1dSLionel Sambuc     struct S {
834*0a6a1f1dSLionel Sambuc       void f();
835*0a6a1f1dSLionel Sambuc     };
836*0a6a1f1dSLionel Sambuc   }
f()837*0a6a1f1dSLionel Sambuc   void N::S::f() {
838*0a6a1f1dSLionel Sambuc     void g(); // expected-note {{previous}}
839*0a6a1f1dSLionel Sambuc   }
840*0a6a1f1dSLionel Sambuc   int g();
841*0a6a1f1dSLionel Sambuc   namespace N {
842*0a6a1f1dSLionel Sambuc     int g(); // expected-error {{cannot be overloaded}}
843*0a6a1f1dSLionel Sambuc   }
844*0a6a1f1dSLionel Sambuc }
845*0a6a1f1dSLionel Sambuc 
846*0a6a1f1dSLionel Sambuc // dr475 FIXME write a codegen test
847*0a6a1f1dSLionel Sambuc 
848*0a6a1f1dSLionel Sambuc namespace dr477 { // dr477: 3.5
849*0a6a1f1dSLionel Sambuc   struct A {
850*0a6a1f1dSLionel Sambuc     explicit A();
851*0a6a1f1dSLionel Sambuc     virtual void f();
852*0a6a1f1dSLionel Sambuc   };
853*0a6a1f1dSLionel Sambuc   struct B {
854*0a6a1f1dSLionel Sambuc     friend explicit A::A(); // expected-error {{'explicit' is invalid in friend declarations}}
855*0a6a1f1dSLionel Sambuc     friend virtual void A::f(); // expected-error {{'virtual' is invalid in friend declarations}}
856*0a6a1f1dSLionel Sambuc   };
A()857*0a6a1f1dSLionel Sambuc   explicit A::A() {} // expected-error {{can only be specified inside the class definition}}
f()858*0a6a1f1dSLionel Sambuc   virtual void A::f() {} // expected-error {{can only be specified inside the class definition}}
859*0a6a1f1dSLionel Sambuc }
860*0a6a1f1dSLionel Sambuc 
861*0a6a1f1dSLionel Sambuc namespace dr478 { // dr478: yes
862*0a6a1f1dSLionel Sambuc   struct A { virtual void f() = 0; }; // expected-note {{unimplemented}}
863*0a6a1f1dSLionel Sambuc   void f(A *a);
864*0a6a1f1dSLionel Sambuc   void f(A a[10]); // expected-error {{array of abstract class type}}
865*0a6a1f1dSLionel Sambuc }
866*0a6a1f1dSLionel Sambuc 
867*0a6a1f1dSLionel Sambuc namespace dr479 { // dr479: yes
868*0a6a1f1dSLionel Sambuc   struct S {
869*0a6a1f1dSLionel Sambuc     S();
870*0a6a1f1dSLionel Sambuc   private:
871*0a6a1f1dSLionel Sambuc     S(const S&); // expected-note +{{here}}
872*0a6a1f1dSLionel Sambuc     ~S(); // expected-note +{{here}}
873*0a6a1f1dSLionel Sambuc   };
f()874*0a6a1f1dSLionel Sambuc   void f() {
875*0a6a1f1dSLionel Sambuc     throw S();
876*0a6a1f1dSLionel Sambuc     // expected-error@-1 {{temporary of type 'dr479::S' has private destructor}}
877*0a6a1f1dSLionel Sambuc     // expected-error@-2 {{calling a private constructor}}
878*0a6a1f1dSLionel Sambuc     // expected-error@-3 {{exception object of type 'dr479::S' has private destructor}}
879*0a6a1f1dSLionel Sambuc #if __cplusplus < 201103L
880*0a6a1f1dSLionel Sambuc     // expected-error@-5 {{C++98 requires an accessible copy constructor}}
881*0a6a1f1dSLionel Sambuc #endif
882*0a6a1f1dSLionel Sambuc   }
g()883*0a6a1f1dSLionel Sambuc   void g() {
884*0a6a1f1dSLionel Sambuc     S s; // expected-error {{private destructor}}}
885*0a6a1f1dSLionel Sambuc     throw s;
886*0a6a1f1dSLionel Sambuc     // expected-error@-1 {{calling a private constructor}}
887*0a6a1f1dSLionel Sambuc     // expected-error@-2 {{exception object of type 'dr479::S' has private destructor}}
888*0a6a1f1dSLionel Sambuc   }
h()889*0a6a1f1dSLionel Sambuc   void h() {
890*0a6a1f1dSLionel Sambuc     try {
891*0a6a1f1dSLionel Sambuc       f();
892*0a6a1f1dSLionel Sambuc       g();
893*0a6a1f1dSLionel Sambuc     } catch (S s) {
894*0a6a1f1dSLionel Sambuc       // expected-error@-1 {{calling a private constructor}}
895*0a6a1f1dSLionel Sambuc       // expected-error@-2 {{variable of type 'dr479::S' has private destructor}}
896*0a6a1f1dSLionel Sambuc     }
897*0a6a1f1dSLionel Sambuc   }
898*0a6a1f1dSLionel Sambuc }
899*0a6a1f1dSLionel Sambuc 
900*0a6a1f1dSLionel Sambuc namespace dr480 { // dr480: yes
901*0a6a1f1dSLionel Sambuc   struct A { int n; };
902*0a6a1f1dSLionel Sambuc   struct B : A {};
903*0a6a1f1dSLionel Sambuc   struct C : virtual B {};
904*0a6a1f1dSLionel Sambuc   struct D : C {};
905*0a6a1f1dSLionel Sambuc 
906*0a6a1f1dSLionel Sambuc   int A::*a = &A::n;
907*0a6a1f1dSLionel Sambuc   int D::*b = a; // expected-error {{virtual base}}
908*0a6a1f1dSLionel Sambuc 
909*0a6a1f1dSLionel Sambuc   extern int D::*c;
910*0a6a1f1dSLionel Sambuc   int A::*d = static_cast<int A::*>(c); // expected-error {{virtual base}}
911*0a6a1f1dSLionel Sambuc 
912*0a6a1f1dSLionel Sambuc   D *e;
913*0a6a1f1dSLionel Sambuc   A *f = e;
914*0a6a1f1dSLionel Sambuc   D *g = static_cast<D*>(f); // expected-error {{virtual base}}
915*0a6a1f1dSLionel Sambuc 
916*0a6a1f1dSLionel Sambuc   extern D &i;
917*0a6a1f1dSLionel Sambuc   A &j = i;
918*0a6a1f1dSLionel Sambuc   D &k = static_cast<D&>(j); // expected-error {{virtual base}}
919*0a6a1f1dSLionel Sambuc }
920*0a6a1f1dSLionel Sambuc 
921*0a6a1f1dSLionel Sambuc namespace dr481 { // dr481: yes
922*0a6a1f1dSLionel Sambuc   template<class T, T U> class A { T *x; };
923*0a6a1f1dSLionel Sambuc   T *x; // expected-error {{unknown type}}
924*0a6a1f1dSLionel Sambuc 
925*0a6a1f1dSLionel Sambuc   template<class T *U> class B { T *x; };
926*0a6a1f1dSLionel Sambuc   T *y; // ok
927*0a6a1f1dSLionel Sambuc 
928*0a6a1f1dSLionel Sambuc   struct C {
929*0a6a1f1dSLionel Sambuc     template<class T> void f(class D *p);
930*0a6a1f1dSLionel Sambuc   };
931*0a6a1f1dSLionel Sambuc   D *z; // ok
932*0a6a1f1dSLionel Sambuc 
933*0a6a1f1dSLionel Sambuc   template<typename A = C, typename C = A> struct E {
fdr481::E934*0a6a1f1dSLionel Sambuc     void f() {
935*0a6a1f1dSLionel Sambuc       typedef ::dr481::C c; // expected-note {{previous}}
936*0a6a1f1dSLionel Sambuc       typedef C c; // expected-error {{different type}}
937*0a6a1f1dSLionel Sambuc     }
938*0a6a1f1dSLionel Sambuc   };
939*0a6a1f1dSLionel Sambuc   template struct E<>; // ok
940*0a6a1f1dSLionel Sambuc   template struct E<int>; // expected-note {{instantiation of}}
941*0a6a1f1dSLionel Sambuc 
942*0a6a1f1dSLionel Sambuc   template<template<typename U_no_typo_correction> class A,
943*0a6a1f1dSLionel Sambuc            A<int> *B,
944*0a6a1f1dSLionel Sambuc            U_no_typo_correction *C> // expected-error {{unknown type}}
945*0a6a1f1dSLionel Sambuc   struct F {
946*0a6a1f1dSLionel Sambuc     U_no_typo_correction *x; // expected-error {{unknown type}}
947*0a6a1f1dSLionel Sambuc   };
948*0a6a1f1dSLionel Sambuc 
949*0a6a1f1dSLionel Sambuc   template<template<class H *> class> struct G {
950*0a6a1f1dSLionel Sambuc     H *x;
951*0a6a1f1dSLionel Sambuc   };
952*0a6a1f1dSLionel Sambuc   H *q;
953*0a6a1f1dSLionel Sambuc 
954*0a6a1f1dSLionel Sambuc   typedef int N;
955*0a6a1f1dSLionel Sambuc   template<N X, typename N, template<N Y> class T> struct I;
956*0a6a1f1dSLionel Sambuc   template<char*> struct J;
957*0a6a1f1dSLionel Sambuc   I<123, char*, J> *j;
958*0a6a1f1dSLionel Sambuc }
959*0a6a1f1dSLionel Sambuc 
960*0a6a1f1dSLionel Sambuc namespace dr482 { // dr482: 3.5
961*0a6a1f1dSLionel Sambuc   extern int a;
962*0a6a1f1dSLionel Sambuc   void f();
963*0a6a1f1dSLionel Sambuc 
964*0a6a1f1dSLionel Sambuc   int dr482::a = 0; // expected-warning {{extra qualification}}
f()965*0a6a1f1dSLionel Sambuc   void dr482::f() {} // expected-warning {{extra qualification}}
966*0a6a1f1dSLionel Sambuc 
967*0a6a1f1dSLionel Sambuc   inline namespace X { // expected-error 0-1{{C++11 feature}}
968*0a6a1f1dSLionel Sambuc     extern int b;
969*0a6a1f1dSLionel Sambuc     void g();
970*0a6a1f1dSLionel Sambuc     struct S;
971*0a6a1f1dSLionel Sambuc   }
972*0a6a1f1dSLionel Sambuc   int dr482::b = 0; // expected-warning {{extra qualification}}
g()973*0a6a1f1dSLionel Sambuc   void dr482::g() {} // expected-warning {{extra qualification}}
974*0a6a1f1dSLionel Sambuc   struct dr482::S {}; // expected-warning {{extra qualification}}
975*0a6a1f1dSLionel Sambuc 
976*0a6a1f1dSLionel Sambuc   void dr482::f(); // expected-warning {{extra qualification}}
977*0a6a1f1dSLionel Sambuc   void dr482::g(); // expected-warning {{extra qualification}}
978*0a6a1f1dSLionel Sambuc 
979*0a6a1f1dSLionel Sambuc   // FIXME: The following are valid in DR482's wording, but these are bugs in
980*0a6a1f1dSLionel Sambuc   // the wording which we deliberately don't implement.
981*0a6a1f1dSLionel Sambuc   namespace N { typedef int type; }
982*0a6a1f1dSLionel Sambuc   typedef int N::type; // expected-error {{typedef declarator cannot be qualified}}
983*0a6a1f1dSLionel Sambuc   struct A {
984*0a6a1f1dSLionel Sambuc     struct B;
985*0a6a1f1dSLionel Sambuc     struct A::B {}; // expected-error {{extra qualification}}
986*0a6a1f1dSLionel Sambuc 
987*0a6a1f1dSLionel Sambuc #if __cplusplus >= 201103L
988*0a6a1f1dSLionel Sambuc     enum class C;
989*0a6a1f1dSLionel Sambuc     enum class A::C {}; // expected-error {{extra qualification}}
990*0a6a1f1dSLionel Sambuc #endif
991*0a6a1f1dSLionel Sambuc   };
992*0a6a1f1dSLionel Sambuc }
993*0a6a1f1dSLionel Sambuc 
994*0a6a1f1dSLionel Sambuc namespace dr483 { // dr483: yes
995*0a6a1f1dSLionel Sambuc   namespace climits {
996*0a6a1f1dSLionel Sambuc     int check1[__SCHAR_MAX__ >= 127 ? 1 : -1];
997*0a6a1f1dSLionel Sambuc     int check2[__SHRT_MAX__ >= 32767 ? 1 : -1];
998*0a6a1f1dSLionel Sambuc     int check3[__INT_MAX__ >= 32767 ? 1 : -1];
999*0a6a1f1dSLionel Sambuc     int check4[__LONG_MAX__ >= 2147483647 ? 1 : -1];
1000*0a6a1f1dSLionel Sambuc     int check5[__LONG_LONG_MAX__ >= 9223372036854775807 ? 1 : -1];
1001*0a6a1f1dSLionel Sambuc #if __cplusplus < 201103L
1002*0a6a1f1dSLionel Sambuc     // expected-error@-2 {{extension}}
1003*0a6a1f1dSLionel Sambuc #endif
1004*0a6a1f1dSLionel Sambuc   }
1005*0a6a1f1dSLionel Sambuc   namespace cstdint {
1006*0a6a1f1dSLionel Sambuc     int check1[__PTRDIFF_WIDTH__ >= 16 ? 1 : -1];
1007*0a6a1f1dSLionel Sambuc     int check2[__SIG_ATOMIC_WIDTH__ >= 8 ? 1 : -1];
1008*0a6a1f1dSLionel Sambuc     int check3[__SIZE_WIDTH__ >= 16 ? 1 : -1];
1009*0a6a1f1dSLionel Sambuc     int check4[__WCHAR_WIDTH__ >= 8 ? 1 : -1];
1010*0a6a1f1dSLionel Sambuc     int check5[__WINT_WIDTH__ >= 16 ? 1 : -1];
1011*0a6a1f1dSLionel Sambuc   }
1012*0a6a1f1dSLionel Sambuc }
1013*0a6a1f1dSLionel Sambuc 
1014*0a6a1f1dSLionel Sambuc namespace dr484 { // dr484: yes
1015*0a6a1f1dSLionel Sambuc   struct A {
1016*0a6a1f1dSLionel Sambuc     A();
1017*0a6a1f1dSLionel Sambuc     void f();
1018*0a6a1f1dSLionel Sambuc   };
1019*0a6a1f1dSLionel Sambuc   typedef const A CA;
f()1020*0a6a1f1dSLionel Sambuc   void CA::f() {
1021*0a6a1f1dSLionel Sambuc     this->~CA();
1022*0a6a1f1dSLionel Sambuc     this->CA::~A();
1023*0a6a1f1dSLionel Sambuc     this->CA::A::~A();
1024*0a6a1f1dSLionel Sambuc   }
A()1025*0a6a1f1dSLionel Sambuc   CA::A() {}
1026*0a6a1f1dSLionel Sambuc 
1027*0a6a1f1dSLionel Sambuc   struct B : CA {
Bdr484::B1028*0a6a1f1dSLionel Sambuc     B() : CA() {}
fdr484::B1029*0a6a1f1dSLionel Sambuc     void f() { return CA::f(); }
1030*0a6a1f1dSLionel Sambuc   };
1031*0a6a1f1dSLionel Sambuc 
1032*0a6a1f1dSLionel Sambuc   struct C;
1033*0a6a1f1dSLionel Sambuc   typedef C CT; // expected-note {{here}}
1034*0a6a1f1dSLionel Sambuc   struct CT {}; // expected-error {{conflicts with typedef}}
1035*0a6a1f1dSLionel Sambuc 
1036*0a6a1f1dSLionel Sambuc   namespace N {
1037*0a6a1f1dSLionel Sambuc     struct D;
1038*0a6a1f1dSLionel Sambuc     typedef D DT; // expected-note {{here}}
1039*0a6a1f1dSLionel Sambuc   }
1040*0a6a1f1dSLionel Sambuc   struct N::DT {}; // expected-error {{conflicts with typedef}}
1041*0a6a1f1dSLionel Sambuc 
1042*0a6a1f1dSLionel Sambuc   typedef struct {
1043*0a6a1f1dSLionel Sambuc     S(); // expected-error {{requires a type}}
1044*0a6a1f1dSLionel Sambuc   } S;
1045*0a6a1f1dSLionel Sambuc }
1046*0a6a1f1dSLionel Sambuc 
1047*0a6a1f1dSLionel Sambuc namespace dr485 { // dr485: yes
1048*0a6a1f1dSLionel Sambuc   namespace N {
1049*0a6a1f1dSLionel Sambuc     struct S {};
1050*0a6a1f1dSLionel Sambuc     int operator+(S, S);
1051*0a6a1f1dSLionel Sambuc     template<typename T> int f(S);
1052*0a6a1f1dSLionel Sambuc   }
1053*0a6a1f1dSLionel Sambuc   template<typename T> int f();
1054*0a6a1f1dSLionel Sambuc 
1055*0a6a1f1dSLionel Sambuc   N::S s;
1056*0a6a1f1dSLionel Sambuc   int a = operator+(s, s);
1057*0a6a1f1dSLionel Sambuc   int b = f<int>(s);
1058*0a6a1f1dSLionel Sambuc }
1059*0a6a1f1dSLionel Sambuc 
1060*0a6a1f1dSLionel Sambuc namespace dr486 { // dr486: yes
1061*0a6a1f1dSLionel Sambuc   template<typename T> T f(T *); // expected-note 2{{substitution failure}}
1062*0a6a1f1dSLionel Sambuc   int &f(...);
1063*0a6a1f1dSLionel Sambuc 
1064*0a6a1f1dSLionel Sambuc   void g();
1065*0a6a1f1dSLionel Sambuc   int n[10];
1066*0a6a1f1dSLionel Sambuc 
h()1067*0a6a1f1dSLionel Sambuc   void h() {
1068*0a6a1f1dSLionel Sambuc     int &a = f(&g);
1069*0a6a1f1dSLionel Sambuc     int &b = f(&n);
1070*0a6a1f1dSLionel Sambuc     f<void()>(&g); // expected-error {{no match}}
1071*0a6a1f1dSLionel Sambuc     f<int[10]>(&n); // expected-error {{no match}}
1072*0a6a1f1dSLionel Sambuc   }
1073*0a6a1f1dSLionel Sambuc }
1074*0a6a1f1dSLionel Sambuc 
1075*0a6a1f1dSLionel Sambuc namespace dr487 { // dr487: yes
1076*0a6a1f1dSLionel Sambuc   enum E { e };
1077*0a6a1f1dSLionel Sambuc   int operator+(int, E);
1078*0a6a1f1dSLionel Sambuc   int i[4 + e]; // expected-error 2{{variable length array}}
1079*0a6a1f1dSLionel Sambuc }
1080*0a6a1f1dSLionel Sambuc 
1081*0a6a1f1dSLionel Sambuc namespace dr488 { // dr488: yes c++11
1082*0a6a1f1dSLionel Sambuc   template <typename T> void f(T);
1083*0a6a1f1dSLionel Sambuc   void f(int);
g()1084*0a6a1f1dSLionel Sambuc   void g() {
1085*0a6a1f1dSLionel Sambuc     // FIXME: It seems CWG thought this should be a SFINAE failure prior to
1086*0a6a1f1dSLionel Sambuc     // allowing local types as template arguments. In C++98, we should either
1087*0a6a1f1dSLionel Sambuc     // allow local types as template arguments or treat this as a SFINAE
1088*0a6a1f1dSLionel Sambuc     // failure.
1089*0a6a1f1dSLionel Sambuc     enum E { e };
1090*0a6a1f1dSLionel Sambuc     f(e);
1091*0a6a1f1dSLionel Sambuc #if __cplusplus < 201103L
1092*0a6a1f1dSLionel Sambuc     // expected-error@-2 {{local type}}
1093*0a6a1f1dSLionel Sambuc #endif
1094*0a6a1f1dSLionel Sambuc   }
1095*0a6a1f1dSLionel Sambuc }
1096*0a6a1f1dSLionel Sambuc 
1097*0a6a1f1dSLionel Sambuc // dr489: na
1098*0a6a1f1dSLionel Sambuc 
1099*0a6a1f1dSLionel Sambuc namespace dr490 { // dr490: yes
1100*0a6a1f1dSLionel Sambuc   template<typename T> struct X {};
1101*0a6a1f1dSLionel Sambuc 
1102*0a6a1f1dSLionel Sambuc   struct A {
1103*0a6a1f1dSLionel Sambuc     typedef int T;
1104*0a6a1f1dSLionel Sambuc     struct K {}; // expected-note {{declared}}
1105*0a6a1f1dSLionel Sambuc 
1106*0a6a1f1dSLionel Sambuc     int f(T);
1107*0a6a1f1dSLionel Sambuc     int g(T);
1108*0a6a1f1dSLionel Sambuc     int h(X<T>);
1109*0a6a1f1dSLionel Sambuc     int X<T>::*i(); // expected-note {{previous}}
1110*0a6a1f1dSLionel Sambuc     int K::*j();
1111*0a6a1f1dSLionel Sambuc 
1112*0a6a1f1dSLionel Sambuc     template<typename T> T k();
1113*0a6a1f1dSLionel Sambuc 
1114*0a6a1f1dSLionel Sambuc     operator X<T>();
1115*0a6a1f1dSLionel Sambuc   };
1116*0a6a1f1dSLionel Sambuc 
1117*0a6a1f1dSLionel Sambuc   struct B {
1118*0a6a1f1dSLionel Sambuc     typedef char T;
1119*0a6a1f1dSLionel Sambuc     typedef int U;
1120*0a6a1f1dSLionel Sambuc     friend int A::f(T);
1121*0a6a1f1dSLionel Sambuc     friend int A::g(U);
1122*0a6a1f1dSLionel Sambuc     friend int A::h(X<T>);
1123*0a6a1f1dSLionel Sambuc 
1124*0a6a1f1dSLionel Sambuc     // FIXME: Per this DR, these two are valid! That is another defect
1125*0a6a1f1dSLionel Sambuc     // (no number yet...) which will eventually supersede this one.
1126*0a6a1f1dSLionel Sambuc     friend int X<T>::*A::i(); // expected-error {{return type}}
1127*0a6a1f1dSLionel Sambuc     friend int K::*A::j(); // expected-error {{undeclared identifier 'K'; did you mean 'A::K'?}}
1128*0a6a1f1dSLionel Sambuc 
1129*0a6a1f1dSLionel Sambuc     // ok, lookup finds B::T, not A::T, so return type matches
1130*0a6a1f1dSLionel Sambuc     friend char A::k<T>();
1131*0a6a1f1dSLionel Sambuc     friend int A::k<U>();
1132*0a6a1f1dSLionel Sambuc 
1133*0a6a1f1dSLionel Sambuc     // A conversion-type-id in a conversion-function-id is always looked up in
1134*0a6a1f1dSLionel Sambuc     // the class of the conversion function first.
1135*0a6a1f1dSLionel Sambuc     friend A::operator X<T>();
1136*0a6a1f1dSLionel Sambuc   };
1137*0a6a1f1dSLionel Sambuc }
1138*0a6a1f1dSLionel Sambuc 
1139*0a6a1f1dSLionel Sambuc namespace dr491 { // dr491: dup 413
1140*0a6a1f1dSLionel Sambuc   struct A {} a, b[3] = { a, {} };
1141*0a6a1f1dSLionel Sambuc   A c[2] = { a, {}, b[1] }; // expected-error {{excess elements}}
1142*0a6a1f1dSLionel Sambuc }
1143*0a6a1f1dSLionel Sambuc 
1144*0a6a1f1dSLionel Sambuc // dr492 FIXME write a codegen test
1145*0a6a1f1dSLionel Sambuc 
1146*0a6a1f1dSLionel Sambuc namespace dr493 { // dr493: dup 976
1147*0a6a1f1dSLionel Sambuc   struct X {
1148*0a6a1f1dSLionel Sambuc     template <class T> operator const T &() const;
1149*0a6a1f1dSLionel Sambuc   };
f()1150*0a6a1f1dSLionel Sambuc   void f() {
1151*0a6a1f1dSLionel Sambuc     if (X()) {
1152*0a6a1f1dSLionel Sambuc     }
1153*0a6a1f1dSLionel Sambuc   }
1154*0a6a1f1dSLionel Sambuc }
1155*0a6a1f1dSLionel Sambuc 
1156*0a6a1f1dSLionel Sambuc namespace dr494 { // dr494: dup 372
1157*0a6a1f1dSLionel Sambuc   class A {
1158*0a6a1f1dSLionel Sambuc     class B {};
1159*0a6a1f1dSLionel Sambuc     friend class C;
1160*0a6a1f1dSLionel Sambuc   };
1161*0a6a1f1dSLionel Sambuc   class C : A::B {
1162*0a6a1f1dSLionel Sambuc     A::B x;
1163*0a6a1f1dSLionel Sambuc     class D : A::B {
1164*0a6a1f1dSLionel Sambuc       A::B y;
1165*0a6a1f1dSLionel Sambuc     };
1166*0a6a1f1dSLionel Sambuc   };
1167*0a6a1f1dSLionel Sambuc }
1168*0a6a1f1dSLionel Sambuc 
1169*0a6a1f1dSLionel Sambuc namespace dr495 { // dr495: 3.5
1170*0a6a1f1dSLionel Sambuc   template<typename T>
1171*0a6a1f1dSLionel Sambuc   struct S {
operator intdr495::S1172*0a6a1f1dSLionel Sambuc     operator int() { return T::error; }
1173*0a6a1f1dSLionel Sambuc     template<typename U> operator U();
1174*0a6a1f1dSLionel Sambuc   };
1175*0a6a1f1dSLionel Sambuc   S<int> s;
1176*0a6a1f1dSLionel Sambuc   long n = s;
1177*0a6a1f1dSLionel Sambuc 
1178*0a6a1f1dSLionel Sambuc   template<typename T>
1179*0a6a1f1dSLionel Sambuc   struct S2 {
1180*0a6a1f1dSLionel Sambuc     template<typename U> operator U();
operator intdr495::S21181*0a6a1f1dSLionel Sambuc     operator int() { return T::error; }
1182*0a6a1f1dSLionel Sambuc   };
1183*0a6a1f1dSLionel Sambuc   S2<int> s2;
1184*0a6a1f1dSLionel Sambuc   long n2 = s2;
1185*0a6a1f1dSLionel Sambuc }
1186*0a6a1f1dSLionel Sambuc 
1187*0a6a1f1dSLionel Sambuc namespace dr496 { // dr496: no
1188*0a6a1f1dSLionel Sambuc   struct A { int n; };
1189*0a6a1f1dSLionel Sambuc   struct B { volatile int n; };
1190*0a6a1f1dSLionel Sambuc   int check1[ __is_trivially_copyable(const int) ? 1 : -1];
1191*0a6a1f1dSLionel Sambuc   int check2[!__is_trivially_copyable(volatile int) ? 1 : -1];
1192*0a6a1f1dSLionel Sambuc   int check3[ __is_trivially_constructible(A, const A&) ? 1 : -1];
1193*0a6a1f1dSLionel Sambuc   // FIXME: This is wrong.
1194*0a6a1f1dSLionel Sambuc   int check4[ __is_trivially_constructible(B, const B&) ? 1 : -1];
1195*0a6a1f1dSLionel Sambuc   int check5[ __is_trivially_assignable(A, const A&) ? 1 : -1];
1196*0a6a1f1dSLionel Sambuc   // FIXME: This is wrong.
1197*0a6a1f1dSLionel Sambuc   int check6[ __is_trivially_assignable(B, const B&) ? 1 : -1];
1198*0a6a1f1dSLionel Sambuc }
1199*0a6a1f1dSLionel Sambuc 
1200*0a6a1f1dSLionel Sambuc namespace dr497 { // dr497: yes
before()1201*0a6a1f1dSLionel Sambuc   void before() {
1202*0a6a1f1dSLionel Sambuc     struct S {
1203*0a6a1f1dSLionel Sambuc       mutable int i;
1204*0a6a1f1dSLionel Sambuc     };
1205*0a6a1f1dSLionel Sambuc     const S cs; // expected-error {{default initialization}} expected-note {{add an explicit initializer}}
1206*0a6a1f1dSLionel Sambuc     int S::*pm = &S::i;
1207*0a6a1f1dSLionel Sambuc     cs.*pm = 88;
1208*0a6a1f1dSLionel Sambuc   }
1209*0a6a1f1dSLionel Sambuc 
after()1210*0a6a1f1dSLionel Sambuc   void after() {
1211*0a6a1f1dSLionel Sambuc     struct S {
1212*0a6a1f1dSLionel Sambuc       S() : i(0) {}
1213*0a6a1f1dSLionel Sambuc       mutable int i;
1214*0a6a1f1dSLionel Sambuc     };
1215*0a6a1f1dSLionel Sambuc     const S cs;
1216*0a6a1f1dSLionel Sambuc     int S::*pm = &S::i;
1217*0a6a1f1dSLionel Sambuc     cs.*pm = 88; // expected-error {{not assignable}}
1218*0a6a1f1dSLionel Sambuc   }
1219*0a6a1f1dSLionel Sambuc }
1220*0a6a1f1dSLionel Sambuc 
1221*0a6a1f1dSLionel Sambuc namespace dr499 { // dr499: yes
1222*0a6a1f1dSLionel Sambuc   extern char str[];
f()1223*0a6a1f1dSLionel Sambuc   void f() { throw str; }
1224*0a6a1f1dSLionel Sambuc }
1225