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