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