1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 
6 namespace dr100 { // dr100: yes
7   template<const char (*)[4]> struct A {}; // expected-note 0-1{{declared here}}
8   template<const char (&)[4]> struct B {}; // expected-note 0-1{{declared here}}
9   template<const char *> struct C {}; // expected-note 0-1{{declared here}}
10   template<const char &> struct D {}; // expected-note 0-1{{declared here}}
11   A<&"foo"> a; // #100a
12   B<"bar"> b; // #100b
13   C<"baz"> c; // #100c
14   D<*"quux"> d; // #100d
15 #if __cplusplus < 201703L
16   // expected-error@#100a {{does not refer to any declaration}}
17   // expected-error@#100b {{does not refer to any declaration}}
18   // expected-error@#100c {{does not refer to any declaration}}
19   // expected-error@#100d {{does not refer to any declaration}}
20 #else
21   // expected-error@#100a {{pointer to string literal is not allowed in a template argument}}
22   // expected-error@#100b {{reference to string literal is not allowed in a template argument}}
23   // expected-error@#100c {{pointer to subobject of string literal is not allowed in a template argument}}
24   // expected-error@#100d {{reference to subobject of string literal is not allowed in a template argument}}
25 #endif
26 }
27 
28 namespace dr101 { // dr101: 3.5
29   extern "C" void dr101_f();
30   typedef unsigned size_t;
31   namespace X {
32     extern "C" void dr101_f();
33     typedef unsigned size_t;
34   }
35   using X::dr101_f;
36   using X::size_t;
37   extern "C" void dr101_f();
38   typedef unsigned size_t;
39 }
40 
41 namespace dr102 { // dr102: yes
42   namespace A {
f(T a,T b)43     template<typename T> T f(T a, T b) { return a + b; } // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
44   }
45   namespace B {
46     struct S {};
47   }
48   B::S operator+(B::S, B::S); // expected-note {{should be declared prior to the call site or in namespace 'dr102::B'}}
49   template B::S A::f(B::S, B::S); // expected-note {{in instantiation of}}
50 }
51 
52 // dr103: na
53 // dr104: na lib
54 // dr105: na
55 
56 namespace dr106 { // dr106: sup 540
57   typedef int &r1;
58   typedef r1 &r1;
59   typedef const r1 r1; // expected-warning {{has no effect}}
60   typedef const r1 &r1; // expected-warning {{has no effect}}
61 
62   typedef const int &r2;
63   typedef r2 &r2;
64   typedef const r2 r2; // expected-warning {{has no effect}}
65   typedef const r2 &r2; // expected-warning {{has no effect}}
66 }
67 
68 namespace dr107 { // dr107: yes
69   struct S {};
operator +(S,S)70   extern "C" S operator+(S, S) { return S(); }
71 }
72 
73 namespace dr108 { // dr108: yes
74   template<typename T> struct A {
75     struct B { typedef int X; };
76     B::X x; // expected-error {{missing 'typename'}}
77     struct C : B { X x; }; // expected-error {{unknown type name}}
78   };
79   template<> struct A<int>::B { int X; };
80 }
81 
82 namespace dr109 { // dr109: yes
83   struct A { template<typename T> void f(T); };
84   template<typename T> struct B : T {
85     using T::template f; // expected-error {{'template' keyword not permitted here}}
86     using T::template f<int>; // expected-error {{'template' keyword not permitted here}} expected-error {{using declaration cannot refer to a template specialization}}
87     // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid.
88     using T::f<int>; // expected-error {{use 'template' keyword}} expected-error {{using declaration cannot refer to a template specialization}}
gdr109::B89     void g() { this->f<int>(123); } // expected-error {{use 'template' keyword}}
90   };
91 }
92 
93 namespace dr111 { // dr111: dup 535
94   struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
95   struct B : A { B(); }; // expected-note +{{would lose const qualifier}} expected-note {{requires 0 arguments}}
96   const B b1;
97   B b2(b1); // expected-error {{no matching constructor}}
98 }
99 
100 namespace dr112 { // dr112: yes
101   struct T { int n; };
102   typedef T Arr[1];
103 
104   const T a1[1] = {};
105   volatile T a2[1] = {};
106   const Arr a3 = {};
107   volatile Arr a4 = {};
108   template<const volatile T*> struct X {};
109   X<a1> x1;
110   X<a2> x2;
111   X<a3> x3;
112   X<a4> x4;
113 #if __cplusplus < 201103L
114   // expected-error@-5 {{internal linkage}} expected-note@-10 {{here}}
115   // expected-error@-4 {{internal linkage}} expected-note@-9 {{here}}
116 #else
117   // FIXME: Test this somehow.
118 #endif
119 }
120 
121 namespace dr113 { // dr113: yes
122   extern void (*p)();
f()123   void f() {
124     no_such_function(); // expected-error {{undeclared}}
125     p();
126   }
127   void g();
128   void (*p)() = &g;
129 }
130 
131 namespace dr114 { // dr114: yes
132   struct A {
133     virtual void f(int) = 0; // expected-note {{unimplemented}}
134   };
135   struct B : A {
136     template<typename T> void f(T);
gdr114::B137     void g() { f(0); }
138   } b; // expected-error {{abstract}}
139 }
140 
141 namespace dr115 { // dr115: yes
142   template<typename T> int f(T); // expected-note +{{}}
143   template<typename T> int g(T); // expected-note +{{}}
144   template<typename T> int g(T, int); // expected-note +{{}}
145 
146   int k1 = f(&f); // expected-error {{no match}}
147   int k2 = f(&f<int>);
148   int k3 = f(&g<int>); // expected-error {{no match}}
149 
h()150   void h() {
151     (void)&f; // expected-error {{address of overloaded function 'f' cannot be cast to type 'void'}}
152     (void)&f<int>;
153     (void)&g<int>; // expected-error {{address of overloaded function 'g' cannot be cast to type 'void'}}
154 
155     &f; // expected-error {{reference to overloaded function could not be resolved}}
156     &f<int>; // expected-warning {{unused}}
157     &g<int>; // expected-error {{reference to overloaded function could not be resolved}}
158   }
159 
160   struct S {
161     template<typename T> static int f(T);
162     template<typename T> static int g(T);
163     template<typename T> static int g(T, int);
164   } s;
165 
166   int k4 = f(&s.f); // expected-error {{non-constant pointer to member}}
167   int k5 = f(&s.f<int>);
168   int k6 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
169 
i()170   void i() {
171     (void)&s.f; // expected-error {{non-constant pointer to member}}
172     (void)&s.f<int>;
173     (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
174 
175     &s.f; // expected-error {{non-constant pointer to member}}
176     &s.f<int>; // expected-warning {{unused}}
177     &s.g<int>; // expected-error {{non-constant pointer to member}}
178   }
179 
180   struct T {
181     template<typename T> int f(T);
182     template<typename T> int g(T);
183     template<typename T> int g(T, int);
184   } t;
185 
186   int k7 = f(&s.f); // expected-error {{non-constant pointer to member}}
187   int k8 = f(&s.f<int>);
188   int k9 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
189 
j()190   void j() {
191     (void)&s.f; // expected-error {{non-constant pointer to member}}
192     (void)&s.f<int>;
193     (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
194 
195     &s.f; // expected-error {{non-constant pointer to member}}
196     &s.f<int>; // expected-warning {{unused}}
197     &s.g<int>; // expected-error {{non-constant pointer to member}}
198   }
199 
200 #if __cplusplus >= 201103L
201   // Special case kicks in only if a template argument list is specified.
202   template<typename T=int> void with_default(); // expected-note +{{}}
203   int k10 = f(&with_default); // expected-error {{no matching function}}
204   int k11 = f(&with_default<>);
k()205   void k() {
206     (void)&with_default; // expected-error {{overloaded function}}
207     (void)&with_default<>;
208     &with_default; // expected-error {{overloaded function}}
209     &with_default<>; // expected-warning {{unused}}
210   }
211 #endif
212 }
213 
214 namespace dr116 { // dr116: yes
215   template<int> struct A {};
f(A<N>)216   template<int N> void f(A<N>) {} // expected-note {{previous}}
f(A<M>)217   template<int M> void f(A<M>) {} // expected-error {{redefinition}}
f(A<sizeof (T)>)218   template<typename T> void f(A<sizeof(T)>) {} // expected-note {{previous}}
f(A<sizeof (U)>)219   template<typename U> void f(A<sizeof(U)>) {} // expected-error {{redefinition}}
220 }
221 
222 // dr117: na
223 // dr118 is in its own file.
224 // dr119: na
225 // dr120: na
226 
227 namespace dr121 { // dr121: yes
228   struct X {
229     template<typename T> struct Y {};
230   };
231   template<typename T> struct Z {
232     X::Y<T> x;
233     T::Y<T> y; // expected-error +{{}}
234   };
235   Z<X> z;
236 }
237 
238 namespace dr122 { // dr122: yes
239   template<typename T> void f();
g()240   void g() { f<int>(); }
241 }
242 
243 // dr123: na
244 // dr124: dup 201
245 
246 // dr125: yes
247 struct dr125_A { struct dr125_B {}; }; // expected-note {{here}}
248 dr125_A::dr125_B dr125_C();
249 namespace dr125_B { dr125_A dr125_C(); }
250 namespace dr125 {
251   struct X {
252     friend dr125_A::dr125_B (::dr125_C)(); // ok
253     friend dr125_A (::dr125_B::dr125_C)(); // ok
254     friend dr125_A::dr125_B::dr125_C(); // expected-error {{did you mean the constructor name 'dr125_B'?}}
255     // expected-error@-1 {{missing exception specification}}
256   };
257 }
258 
259 namespace dr126 { // dr126: partial
260   // FIXME: We do not yet generate correct code for this change:
261   // eg:
262   //   catch (void*&) should catch void* but not int*
263   //   catch (void*) and catch (void*const&) should catch both
264   // Likewise:
265   //   catch (Base *&) should catch Base* but not Derived*
266   //   catch (Base *) should catch both
267   // In each case, we emit the same code for both catches.
268   //
269   // The ABI does not let us represent the language rule in the unwind tables.
270   // So, when catching by non-const (or volatile) reference to pointer, we
271   // should compare the exception type to the caught type and only accept an
272   // exact match.
273 #if __cplusplus <= 201402L
274   struct C {};
275   struct D : C {};
276   struct E : private C { friend class A; friend class B; };
277   struct F : protected C {};
278   struct G : C {};
279   struct H : D, G {};
280 
281   struct A {
282     virtual void cp() throw(C*);
283     virtual void dp() throw(C*);
284     virtual void ep() throw(C*); // expected-note {{overridden}}
285     virtual void fp() throw(C*); // expected-note {{overridden}}
286     virtual void gp() throw(C*);
287     virtual void hp() throw(C*); // expected-note {{overridden}}
288 
289     virtual void cr() throw(C&);
290     virtual void dr() throw(C&);
291     virtual void er() throw(C&); // expected-note {{overridden}}
292     virtual void fr() throw(C&); // expected-note {{overridden}}
293     virtual void gr() throw(C&);
294     virtual void hr() throw(C&); // expected-note {{overridden}}
295 
296     virtual void pv() throw(void*);
297 
298 #if __cplusplus >= 201103L
299     virtual void np() throw(C*);
300     virtual void npm() throw(int C::*);
301     virtual void nr() throw(C*&); // expected-note {{overridden}}
302     virtual void ncr() throw(C*const&);
303 #endif
304 
305     virtual void ref1() throw(C *const&);
306     virtual void ref2() throw(C *);
307 
308     virtual void v() throw(int);
309     virtual void w() throw(const int);
310     virtual void x() throw(int*); // expected-note {{overridden}}
311     virtual void y() throw(const int*);
312     virtual void z() throw(int); // expected-note {{overridden}}
313   };
314   struct B : A {
315     virtual void cp() throw(C*);
316     virtual void dp() throw(D*);
317     virtual void ep() throw(E*); // expected-error {{more lax}}
318     virtual void fp() throw(F*); // expected-error {{more lax}}
319     virtual void gp() throw(G*);
320     virtual void hp() throw(H*); // expected-error {{more lax}}
321 
322     virtual void cr() throw(C&);
323     virtual void dr() throw(D&);
324     virtual void er() throw(E&); // expected-error {{more lax}}
325     virtual void fr() throw(F&); // expected-error {{more lax}}
326     virtual void gr() throw(G&);
327     virtual void hr() throw(H&); // expected-error {{more lax}}
328 
329     virtual void pv() throw(C*);
330 
331 #if __cplusplus >= 201103L
332     using nullptr_t = decltype(nullptr);
333     virtual void np() throw(nullptr_t);
334     virtual void npm() throw(nullptr_t&);
335     virtual void nr() throw(nullptr_t); // expected-error {{more lax}}
336     virtual void ncr() throw(nullptr_t);
337 #endif
338 
339     virtual void ref1() throw(D *const &);
340     virtual void ref2() throw(D *);
341 
342     virtual void v() throw(const int);
343     virtual void w() throw(int);
344     virtual void x() throw(const int*); // expected-error {{more lax}}
345     virtual void y() throw(int*); // ok
346     virtual void z() throw(long); // expected-error {{more lax}}
347   };
348 #else
349   void f() throw(int); // expected-error {{ISO C++17 does not allow}} expected-note {{use 'noexcept}}
350 #endif
351 }
352 
353 namespace dr127 { // dr127: yes
354   __extension__ typedef __decltype(sizeof(0)) size_t;
355   template<typename T> struct A {
Adr127::A356     A() { throw 0; }
357     void *operator new(size_t, const char * = 0);
operator deletedr127::A358     void operator delete(void *, const char *) { T::error; } // expected-error 2{{no members}}
operator deletedr127::A359     void operator delete(void *) { T::error; }
360   };
361   A<void> *p = new A<void>; // expected-note {{instantiat}}
362   A<int> *q = new ("") A<int>; // expected-note {{instantiat}}
363 }
364 
365 namespace dr128 { // dr128: yes
366   enum E1 { e1 } x = e1;
367   enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);
368 }
369 
370 // dr129: dup 616
371 // dr130: na
372 
373 namespace dr131 { // dr131: sup P1949
374   const char *a_with_\u0e8c = "\u0e8c";
375   const char *b_with_\u0e8d = "\u0e8d";
376   const char *c_with_\u0e8e = "\u0e8e";
377 }
378 
379 namespace dr132 { // dr132: no
f()380   void f() {
381     extern struct {} x; // ok
382     extern struct S {} y; // FIXME: This is invalid.
383   }
384   static enum { E } e;
385 }
386 
387 // dr133: dup 87
388 // dr134: na
389 
390 namespace dr135 { // dr135: yes
391   struct A {
fdr135::A392     A f(A a) { return a; }
g(A a)393     friend A g(A a) { return a; }
hdr135::A394     static A h(A a) { return a; }
395   };
396 }
397 
398 namespace dr136 { // dr136: 3.4
399   void f(int, int, int = 0); // expected-note {{previous declaration is here}}
400   void g(int, int, int); // expected-note {{previous declaration is here}}
401   struct A {
402     friend void f(int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
403     friend void g(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
404     friend void h(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}}
i(int,int,int=0)405     friend void i(int, int, int = 0) {} // expected-note {{previous declaration is here}}
j(int,int,int=0)406     friend void j(int, int, int = 0) {}
407     operator int();
408   };
409   void i(int, int, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
q()410   void q() {
411     j(A(), A()); // ok, has default argument
412   }
413   extern "C" void k(int, int, int, int); // expected-note 2{{previous declaration is here}}
414   namespace NSA {
415   struct A {
416     friend void dr136::k(int, int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
417   };
418   }
419   namespace NSB {
420   struct A {
421     friend void dr136::k(int, int, int = 0, int); // expected-error {{missing default argument on parameter}} expected-error {{must be the only declaration}}
422   };
423   }
424   struct B {
425     void f(int); // expected-note {{previous declaration is here}}
426   };
427   struct C {
428     friend void B::f(int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
429   };
430 }
431 
432 namespace dr137 { // dr137: yes
433   extern void *p;
434   extern const void *cp;
435   extern volatile void *vp;
436   extern const volatile void *cvp;
437   int *q = static_cast<int*>(p);
438   int *qc = static_cast<int*>(cp); // expected-error {{casts away qualifiers}}
439   int *qv = static_cast<int*>(vp); // expected-error {{casts away qualifiers}}
440   int *qcv = static_cast<int*>(cvp); // expected-error {{casts away qualifiers}}
441   const int *cq = static_cast<const int*>(p);
442   const int *cqc = static_cast<const int*>(cp);
443   const int *cqv = static_cast<const int*>(vp); // expected-error {{casts away qualifiers}}
444   const int *cqcv = static_cast<const int*>(cvp); // expected-error {{casts away qualifiers}}
445   const volatile int *cvq = static_cast<const volatile int*>(p);
446   const volatile int *cvqc = static_cast<const volatile int*>(cp);
447   const volatile int *cvqv = static_cast<const volatile int*>(vp);
448   const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
449 }
450 
451 namespace dr139 { // dr139: yes
452   namespace example1 {
453     typedef int f; // expected-note {{previous}}
454     struct A {
455       friend void f(A &); // expected-error {{different kind of symbol}}
456     };
457   }
458 
459   namespace example2 {
460     typedef int f;
461     namespace N {
462       struct A {
463         friend void f(A &);
464         operator int();
gdr139::example2::N::A465         void g(A a) { int i = f(a); } // ok, f is typedef not friend function
466       };
467     }
468   }
469 }
470 
471 namespace dr140 { // dr140: yes
f(int * const)472   void f(int *const) {} // expected-note {{previous}}
f(int[3])473   void f(int[3]) {} // expected-error {{redefinition}}
474   void g(const int);
g(int n)475   void g(int n) { n = 2; }
476 }
477 
478 namespace dr141 { // dr141: yes
479   template<typename T> void f();
480   template<typename T> struct S { int n; }; // expected-note {{'::dr141::S<int>::n' declared here}}
481   struct A : S<int> {
482     template<typename T> void f();
483     template<typename T> struct S {};
484   } a;
485   struct B : S<int> {} b;
g()486   void g() {
487     a.f<int>();
488     (void)a.S<int>::n; // expected-error {{no member named 'n' in 'dr141::A::S<int>'; did you mean '::dr141::S<int>::n'?}}
489 #if __cplusplus < 201103L
490     // expected-error@-2 {{ambiguous}}
491     // expected-note@-11 {{lookup from the current scope}}
492     // expected-note@-9 {{lookup in the object type}}
493 #endif
494     b.f<int>(); // expected-error {{no member}} expected-error +{{}}
495     (void)b.S<int>::n;
496   }
497   template<typename T> struct C {
498     T t;
gdr141::C499     void g() {
500       t.f<int>(); // expected-error {{use 'template'}}
501     }
hdr141::C502     void h() {
503       (void)t.S<int>::n; // ok
504     }
idr141::C505     void i() {
506       (void)t.S<int>(); // ok!
507     }
508   };
h()509   void h() { C<B>().h(); } // ok
510   struct X {
511     template<typename T> void S();
512   };
i()513   void i() { C<X>().i(); } // ok!!
514 }
515 
516 namespace dr142 { // dr142: yes
517   class B { // expected-note +{{here}}
518   public:
519     int mi; // expected-note +{{here}}
520     static int si; // expected-note +{{here}}
521   };
522   class D : private B { // expected-note +{{here}}
523   };
524   class DD : public D {
525     void f();
526   };
f()527   void DD::f() {
528     mi = 3; // expected-error {{private member}}
529     si = 3; // expected-error {{private member}}
530     B b_old; // expected-error {{private member}}
531     dr142::B b;
532     b.mi = 3;
533     b.si = 3;
534     B::si = 3; // expected-error {{private member}}
535     dr142::B::si = 3;
536     B *bp1_old = this; // expected-error {{private member}} expected-error {{private base class}}
537     dr142::B *bp1 = this; // expected-error {{private base class}}
538     B *bp2_old = (B*)this; // expected-error 2{{private member}}
539     dr142::B *bp2 = (dr142::B*)this;
540     bp2->mi = 3;
541   }
542 }
543 
544 namespace dr143 { // dr143: yes
545   namespace A { struct X; }
546   namespace B { void f(A::X); }
547   namespace A {
548     struct X { friend void B::f(X); };
549   }
g(A::X x)550   void g(A::X x) {
551     f(x); // expected-error {{undeclared identifier 'f'}}
552   }
553 }
554 
555 namespace dr145 { // dr145: yes
f(bool b)556   void f(bool b) {
557 #if __cplusplus <= 201402L
558     ++b; // expected-warning {{deprecated}}
559     b++; // expected-warning {{deprecated}}
560 #else
561     ++b; // expected-error {{increment}}
562     b++; // expected-error {{increment}}
563 #endif
564   }
565 }
566 
567 namespace dr147 { // dr147: yes
568   namespace example1 {
569     template<typename> struct A {
570       template<typename T> A(T);
571     };
572     // Per core issue 1435, this is ill-formed because A<int>::A<int> does not
573     // name the injected-class-name. (A<int>::A does, though.)
A(int)574     template<> template<> A<int>::A<int>(int) {} // expected-error {{out-of-line constructor for 'A' cannot have template arguments}}
A(float)575     template<> template<> A<float>::A(float) {}
576   }
577   namespace example2 {
578     struct A { A(); };
579     struct B : A { B(); };
580     A::A a1; // expected-error {{is a constructor}}
581     B::A a2;
582   }
583   namespace example3 {
584     template<typename> struct A {
585       template<typename T> A(T);
586       static A a;
587     };
588     template<> A<int>::A<int>(A<int>::a); // expected-error {{is a constructor}}
589   }
590 }
591 
592 namespace dr148 { // dr148: yes
593   struct A { int A::*p; };
594   int check1[__is_pod(int(A::*)) ? 1 : -1];
595   int check2[__is_pod(A) ? 1 : -1];
596 }
597 
598 // dr149: na
599 
600 namespace dr151 { // dr151: yes
601   struct X {};
602   typedef int X::*p;
603 #if __cplusplus < 201103L
604 #define fold(x) (__builtin_constant_p(0) ? (x) : (x))
605 #else
606 #define fold
607 #endif
608   int check[fold(p() == 0) ? 1 : -1];
609 #undef fold
610 }
611 
612 namespace dr152 { // dr152: yes
613   struct A {
614     A(); // expected-note 0-2{{not viable}}
615     explicit A(const A&); // expected-note 1-2{{not a candidate}}
616   };
617   A a1 = A();
618 #if __cplusplus <= 201402L
619   // expected-error@-2 {{no matching constructor}}
620 #endif
621   A a2((A()));
622 
623   A &f();
624   A a3 = f(); // expected-error {{no matching constructor}}
625   A a4(f());
626 }
627 
628 // dr153: na
629 
630 namespace dr154 { // dr154: yes
631   union { int a; }; // expected-error {{must be declared 'static'}}
632   namespace {
633     union { int b; };
634   }
635   static union { int c; };
636 }
637 
638 namespace dr155 { // dr155: dup 632
639   struct S { int n; } s = { { 1 } }; // expected-warning {{braces around scalar initializer}}
640 }
641 
642 // dr158 is in its own file.
643 
644 namespace dr159 { // dr159: 3.5
645   namespace X { void f(); }
646   void f();
f()647   void dr159::f() {} // expected-warning {{extra qualification}}
f()648   void dr159::X::f() {}
649 }
650 
651 // dr160: na
652 
653 namespace dr161 { // dr161: yes
654   class A {
655   protected:
656     struct B { int n; } b; // expected-note 2{{here}}
657     static B bs;
658     void f(); // expected-note {{here}}
659     static void sf();
660   };
661   struct C : A {};
662   struct D : A {
gdr161::D663     void g(C c) {
664       (void)b.n;
665       B b1;
666       C::B b2; // ok, accessible as a member of A
667       (void)&C::b; // expected-error {{protected}}
668       (void)&C::bs;
669       (void)c.b; // expected-error {{protected}}
670       (void)c.bs;
671       f();
672       sf();
673       c.f(); // expected-error {{protected}}
674       c.sf();
675       A::f();
676       D::f();
677       A::sf();
678       C::sf();
679       D::sf();
680     }
681   };
682 }
683 
684 namespace dr162 { // dr162: no
685   struct A {
686     char &f(char);
687     static int &f(int);
688 
gdr162::A689     void g() {
690       int &a = (&A::f)(0); // FIXME: expected-error {{could not be resolved}}
691       char &b = (&A::f)('0'); // expected-error {{could not be resolved}}
692     }
693   };
694 
695   int &c = (&A::f)(0); // FIXME: expected-error {{could not be resolved}}
696   char &d = (&A::f)('0'); // expected-error {{could not be resolved}}
697 }
698 
699 // dr163: na
700 
701 namespace dr164 { // dr164: yes
702   void f(int);
g(T t)703   template <class T> int g(T t) { return f(t); }
704 
705   enum E { e };
706   int f(E);
707 
708   int k = g(e);
709 }
710 
711 namespace dr165 { // dr165: no
712   namespace N {
713     struct A { friend struct B; };
f()714     void f() { void g(); }
715   }
716   // FIXME: dr1477 says this is ok, dr165 says it's ill-formed
717   struct N::B {};
718   // FIXME: dr165 says this is ill-formed, but the argument in dr1477 says it's ok
g()719   void N::g() {}
720 }
721 
722 namespace dr166 { // dr166: yes
723   namespace A { class X; }
724 
f(T t)725   template<typename T> int f(T t) { return t.n; }
726   int g(A::X);
h(T t)727   template<typename T> int h(T t) { return t.n; } // expected-error {{private}}
728   int i(A::X);
729 
730   namespace A {
731     class X {
732       friend int f<X>(X);
733       friend int dr166::g(X);
734       friend int h(X);
735       friend int i(X);
736       int n; // expected-note 2{{here}}
737     };
738 
h(X x)739     int h(X x) { return x.n; }
i(X x)740     int i(X x) { return x.n; }
741   }
742 
743   template int f(A::X);
g(A::X x)744   int g(A::X x) { return x.n; }
745   template int h(A::X); // expected-note {{instantiation}}
i(A::X x)746   int i(A::X x) { return x.n; } // expected-error {{private}}
747 }
748 
749 // dr167: sup 1012
750 
751 namespace dr168 { // dr168: no
752   extern "C" typedef int (*p)();
753   extern "C++" typedef int (*q)();
754   struct S {
755     static int f();
756   };
757   p a = &S::f; // FIXME: this should fail.
758   q b = &S::f;
759 }
760 
761 namespace dr169 { // dr169: yes
762   template<typename> struct A { int n; };
763   struct B {
764     template<typename> struct C;
765     template<typename> void f();
766     template<typename> static int n; // expected-error 0-1{{extension}}
767   };
768   struct D : A<int>, B {
769     using A<int>::n;
770     using B::C<int>; // expected-error {{using declaration cannot refer to a template specialization}}
771     using B::f<int>; // expected-error {{using declaration cannot refer to a template specialization}}
772     using B::n<int>; // expected-error {{using declaration cannot refer to a template specialization}}
773   };
774 }
775 
776 namespace { // dr171: yes
777   int dr171a;
778 }
779 int dr171b; // expected-note {{here}}
780 namespace dr171 {
781   extern "C" void dr171a();
782   extern "C" void dr171b(); // expected-error {{conflicts}}
783 }
784 
785 namespace dr172 { // dr172: yes
786   enum { zero };
787   int check1[-1 < zero ? 1 : -1];
788 
789   enum { x = -1, y = (unsigned int)-1 };
790   int check2[sizeof(x) > sizeof(int) ? 1 : -1];
791 
792   enum { a = (unsigned int)-1 / 2 };
793   int check3a[sizeof(a) == sizeof(int) ? 1 : -1];
794   int check3b[-a < 0 ? 1 : -1];
795 
796   enum { b = (unsigned int)-1 / 2 + 1 };
797   int check4a[sizeof(b) == sizeof(unsigned int) ? 1 : -1];
798   int check4b[-b > 0 ? 1 : -1];
799 
800   enum { c = (unsigned long)-1 / 2 };
801   int check5a[sizeof(c) == sizeof(long) ? 1 : -1];
802   int check5b[-c < 0 ? 1 : -1];
803 
804   enum { d = (unsigned long)-1 / 2 + 1 };
805   int check6a[sizeof(d) == sizeof(unsigned long) ? 1 : -1];
806   int check6b[-d > 0 ? 1 : -1];
807 
808   enum { e = (unsigned long long)-1 / 2 }; // expected-error 0-1{{extension}}
809   int check7a[sizeof(e) == sizeof(long) ? 1 : -1]; // expected-error 0-1{{extension}}
810   int check7b[-e < 0 ? 1 : -1];
811 
812   enum { f = (unsigned long long)-1 / 2 + 1 }; // expected-error 0-1{{extension}}
813   int check8a[sizeof(f) == sizeof(unsigned long) ? 1 : -1]; // expected-error 0-1{{extension}}
814   int check8b[-f > 0 ? 1 : -1];
815 }
816 
817 namespace dr173 { // dr173: yes
818   int check[('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
819              '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
820              '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9') ? 1 : -1];
821 }
822 
823 // dr174: sup 1012
824 
825 namespace dr175 { // dr175: yes
826   struct A {}; // expected-note {{here}}
827   struct B : private A {}; // expected-note {{constrained by private inheritance}}
828   struct C : B {
829     A a; // expected-error {{private}}
830     dr175::A b;
831   };
832 }
833 
834 namespace dr176 { // dr176: yes
835   template<typename T> class Y;
836   template<> class Y<int> {
f()837     void f() {
838       typedef Y A; // expected-note {{here}}
839       typedef Y<char> A; // expected-error {{different types ('Y<char>' vs 'Y<int>')}}
840     }
841   };
842 
843   template<typename T> struct Base {}; // expected-note 2{{found}}
844   template<typename T> struct Derived : public Base<T> {
fdr176::Derived845     void f() {
846       typedef typename Derived::template Base<T> A;
847       typedef typename Derived::Base A;
848     }
849   };
850   template struct Derived<int>;
851 
852   template<typename T> struct Derived2 : Base<int>, Base<char> {
853     typename Derived2::Base b; // expected-error {{found in multiple base classes}}
854     typename Derived2::Base<double> d;
855   };
856 
857   template<typename T> class X { // expected-note {{here}}
858     X *p1;
859     X<T> *p2;
860     X<int> *p3;
861     dr176::X *p4; // expected-error {{requires template arguments}}
862   };
863 }
864 
865 namespace dr177 { // dr177: yes
866   struct B {};
867   struct A {
868     A(A &); // expected-note 0-1{{not viable: expects an lvalue}}
869     A(const B &); // expected-note 0-1{{not viable: no known conversion from 'dr177::A' to}}
870   };
871   B b;
872   A a = b;
873 #if __cplusplus <= 201402L
874   // expected-error@-2 {{no viable constructor copying variable}}
875 #endif
876 
877   struct C { C(C&); }; // expected-note {{not viable: expects an lvalue for 1st argument}}
878   struct D : C {};
879   struct E { operator D(); };
880   E e;
881   C c = e; // expected-error {{no viable constructor copying variable of type 'dr177::D'}}
882 }
883 
884 namespace dr178 { // dr178: yes
885   int check[int() == 0 ? 1 : -1];
886 #if __cplusplus >= 201103L
887   static_assert(int{} == 0, "");
888   struct S { int a, b; };
889   static_assert(S{1}.b == 0, "");
Tdr178::T890   struct T { constexpr T() : n() {} int n; };
891   static_assert(T().n == 0, "");
Udr178::U892   struct U : S { constexpr U() : S() {} };
893   static_assert(U().b == 0, "");
894 #endif
895 }
896 
897 namespace dr179 { // dr179: yes
898   void f();
899   int n = &f - &f; // expected-error {{arithmetic on pointers to the function type 'void ()'}}
900 }
901 
902 namespace dr180 { // dr180: yes
903   template<typename T> struct X : T, T::some_base {
Xdr180::X904     X() : T::some_type_that_might_be_T(), T::some_base() {}
905     friend class T::some_class;
fdr180::X906     void f() {
907       enum T::some_enum e;
908     }
909   };
910 }
911 
912 namespace dr181 { // dr181: yes
913   namespace X {
914     template <template X<class T> > struct A { }; // expected-error +{{}}
915     template <template X<class T> > void f(A<X>) { } // expected-error +{{}}
916   }
917 
918   namespace Y {
919     template <template <class T> class X> struct A { };
920     template <template <class T> class X> void f(A<X>) { }
921   }
922 }
923 
924 namespace dr182 { // dr182: yes
925   template <class T> struct C {
926     void f();
927     void g();
928   };
929 
930   template <class T> void C<T>::f() {}
931   template <class T> void C<T>::g() {}
932 
933   class A {
934     class B {};
935     void f();
936   };
937 
938   template void C<A::B>::f();
939   template <> void C<A::B>::g();
940 
941   void A::f() {
942     C<B> cb;
943     cb.f();
944   }
945 }
946 
947 namespace dr183 { // dr183: sup 382
948   template<typename T> struct A {};
949   template<typename T> struct B {
950     typedef int X;
951   };
952   template<> struct A<int> {
953 #if __cplusplus <= 199711
954     typename B<int>::X x; // expected-error {{'typename' occurs outside of a template}}
955 #else
956     typename B<int>::X x;
957 #endif
958   };
959 }
960 
961 namespace dr184 { // dr184: yes
962   template<typename T = float> struct B {};
963 
964   template<template<typename TT = float> class T> struct A {
965     void f();
966     void g();
967   };
968 
969   template<template<typename TT> class T> void A<T>::f() { // expected-note {{here}}
970     T<> t; // expected-error {{too few template arguments}}
971   }
972 
973   template<template<typename TT = char> class T> void A<T>::g() {
974     T<> t;
975     typedef T<> X;
976     typedef T<char> X;
977   }
978 
979   void h() { A<B>().g(); }
980 }
981 
982 // dr185 FIXME: add codegen test
983 
984 namespace dr187 { // dr187: sup 481
985   const int Z = 1;
986   template<int X = Z, int Z = X> struct A;
987   typedef A<> T;
988   typedef A<1, 1> T;
989 }
990 
991 namespace dr188 { // dr188: yes
992   char c[10];
993   int check[sizeof(0, c) == 10 ? 1 : -1];
994 }
995 
996 // dr190 FIXME: add codegen test for tbaa
997 
998 // dr193 FIXME: add codegen test
999 
1000 namespace dr194 { // dr194: yes
1001   struct A {
1002     A();
1003     void A(); // expected-error {{constructor cannot have a return type}}
1004   };
1005   struct B {
1006     void B(); // expected-error {{constructor cannot have a return type}}
1007     B();
1008   };
1009   struct C {
1010     inline explicit C(int) {}
1011   };
1012 }
1013 
1014 namespace dr195 { // dr195: yes
1015   void f();
1016   int *p = (int*)&f; // expected-error 0-1{{extension}}
1017   void (*q)() = (void(*)())&p; // expected-error 0-1{{extension}}
1018 }
1019 
1020 namespace dr197 { // dr197: yes
1021   char &f(char);
1022 
1023   template <class T> void g(T t) {
1024     char &a = f(1);
1025     char &b = f(T(1)); // expected-error {{unrelated type 'int'}}
1026     char &c = f(t); // expected-error {{unrelated type 'int'}}
1027   }
1028 
1029   void f(int);
1030 
1031   enum E { e };
1032   int &f(E);
1033 
1034   void h() {
1035     g('a');
1036     g(2);
1037     g(e); // expected-note {{in instantiation of}}
1038   }
1039 }
1040 
1041 namespace dr198 { // dr198: yes
1042   struct A {
1043     int n;
1044     struct B {
1045       int m[sizeof(n)];
1046 #if __cplusplus < 201103L
1047       // expected-error@-2 {{invalid use of non-static data member}}
1048 #endif
1049       int f() { return n; }
1050       // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
1051     };
1052     struct C;
1053     struct D;
1054   };
1055   struct A::C {
1056     int m[sizeof(n)];
1057 #if __cplusplus < 201103L
1058     // expected-error@-2 {{invalid use of non-static data member}}
1059 #endif
1060     int f() { return n; }
1061     // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1062   };
1063   struct A::D : A {
1064     int m[sizeof(n)];
1065 #if __cplusplus < 201103L
1066     // expected-error@-2 {{invalid use of non-static data member}}
1067 #endif
1068     int f() { return n; }
1069   };
1070 }
1071 
1072 // dr199 FIXME: add codegen test
1073