• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -triple %itanium_abi_triple -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 
6 namespace dr300 { // dr300: yes
f(R (&)(A))7   template<typename R, typename A> void f(R (&)(A)) {}
8   int g(int);
h()9   void h() { f(g); }
10 }
11 
12 namespace dr301 { // dr301: yes
13   // see also dr38
14   struct S;
15   template<typename T> void operator+(T, T);
16   void operator-(S, S);
17 
f()18   void f() {
19     bool a = (void(*)(S, S))operator+<S> <
20              (void(*)(S, S))operator+<S>;
21     bool b = (void(*)(S, S))operator- <
22              (void(*)(S, S))operator-;
23     bool c = (void(*)(S, S))operator+ <
24              (void(*)(S, S))operator-; // expected-error {{expected '>'}}
25   }
26 
f()27   template<typename T> void f() {
28     typename T::template operator+<int> a; // expected-error {{typename specifier refers to a non-type template}} expected-error +{{}}
29     // FIXME: This shouldn't say (null).
30     class T::template operator+<int> b; // expected-error {{identifier followed by '<' indicates a class template specialization but (null) refers to a function template}}
31     enum T::template operator+<int> c; // expected-error {{expected identifier}} expected-error {{does not declare anything}}
32     enum T::template operator+<int>::E d; // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}} expected-error {{forward reference}}
33     enum T::template X<int>::E e;
34     T::template operator+<int>::foobar(); // expected-error {{qualified name refers into a specialization of function template 'T::template operator +'}}
35     T::template operator+<int>(0); // ok
36   }
37 
38   template<typename T> class operator&<T*> {}; // expected-error +{{}}
39   template<typename T> class T::operator& {}; // expected-error +{{}}
40   template<typename T> class S::operator&<T*> {}; // expected-error +{{}}
41 }
42 
43 namespace dr302 { // dr302: yes
44   struct A { A(); ~A(); };
45 #if __cplusplus < 201103L
46   struct B { // expected-error {{implicit default constructor for 'dr302::B' must explicitly initialize the const member 'n'}}
47     const int n; // expected-note {{declared here}}
48     A a;
49   } b = B(); // expected-note {{first required here}}
50   // Trivial default constructor C::C() is not called here.
51   struct C {
52     const int n;
53   } c = C();
54 #else
55   struct B {
56     const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
57     A a;
58   } b = B(); // expected-error {{call to implicitly-deleted default constructor}}
59   // C::C() is called here, because even though it's trivial, it's deleted.
60   struct C {
61     const int n; // expected-note {{deleted because field 'n' of const-qualified type 'const int' would not be initialized}}
62   } c = C(); // expected-error {{call to implicitly-deleted default constructor}}
63   struct D {
64     const int n = 0;
65   } d = D();
66 #endif
67 }
68 
69 // dr303: na
70 
71 namespace dr304 { // dr304: yes
72   typedef int &a;
73   int n = a(); // expected-error {{requires an initializer}}
74 
75   struct S { int &b; };
76   int m = S().b;
77 #if __cplusplus < 201103L
78   // expected-error@-3 {{requires an initializer}}
79   // expected-note@-3 {{in value-initialization}}
80 #else
81   // expected-error@-5 {{deleted}}
82   // expected-note@-7 {{reference}}
83 #endif
84 }
85 
86 namespace dr305 { // dr305: no
87   struct A {
88     typedef A C;
89   };
f(A * a)90   void f(A *a) {
91     struct A {};
92     a->~A();
93     a->~C();
94   }
95   typedef A B;
g(B * b)96   void g(B *b) {
97     b->~B();
98     b->~C();
99   }
h(B * b)100   void h(B *b) {
101     struct B {}; // expected-note {{declared here}}
102     b->~B(); // expected-error {{does not match}}
103   }
104 
105   template<typename T> struct X {};
i(X<int> * x)106   void i(X<int>* x) {
107     struct X {};
108     x->~X<int>();
109     x->~X();
110     x->~X<char>(); // expected-error {{no member named}}
111   }
112 
113 #if __cplusplus >= 201103L
114   struct Y {
115     template<typename T> using T1 = Y;
116   };
117   template<typename T> using T2 = Y;
j(Y * y)118   void j(Y *y) {
119     y->~T1<int>();
120     y->~T2<int>();
121   }
122   struct Z {
123     template<typename T> using T2 = T;
124   };
k(Z * z)125   void k(Z *z) {
126     // FIXME: This diagnostic is terrible.
127     z->~T1<int>(); // expected-error {{'T1' following the 'template' keyword does not refer to a template}} expected-error +{{}}
128     z->~T2<int>(); // expected-error {{no member named '~int'}}
129     z->~T2<Z>();
130   }
131 
132   // FIXME: This is valid.
133   namespace Q {
134     template<typename A> struct R {};
135   }
136   template<typename A> using R = Q::R<int>;
qr(Q::R<int> x)137   void qr(Q::R<int> x) { x.~R<char>(); } // expected-error {{no member named}}
138 #endif
139 }
140 
141 namespace dr306 { // dr306: no
142   // FIXME: dup 39
143   // FIXME: This should be accepted.
144   struct A { struct B {}; }; // expected-note 2{{member}}
145   struct C { typedef A::B B; }; // expected-note {{member}}
146   struct D : A, A::B, C {};
147   D::B b; // expected-error {{found in multiple base classes of different types}}
148 }
149 
150 // dr307: na
151 
152 namespace dr308 { // dr308: yes
153   // This is mostly an ABI library issue.
154   struct A {};
155   struct B : A {};
156   struct C : A {};
157   struct D : B, C {};
f()158   void f() {
159     try {
160       throw D();
161     } catch (const A&) { // expected-note {{for type 'const dr308::A &'}}
162       // unreachable
163     } catch (const B&) { // expected-warning {{exception of type 'const dr308::B &' will be caught by earlier handler}}
164       // get here instead
165     }
166   }
167 }
168 
169 // dr309: dup 485
170 
171 namespace dr311 { // dr311: yes
172   namespace X { namespace Y {} }
173   namespace X::Y {}
174 #if __cplusplus <= 201402L
175   // expected-error@-2 {{define each namespace separately}}
176 #endif
177   namespace X {
178     namespace X::Y {}
179 #if __cplusplus <= 201402L
180   // expected-error@-2 {{define each namespace separately}}
181 #endif
182   }
183   // FIXME: The diagnostics here are not very good.
184   namespace ::dr311::X {} // expected-error 2+{{}} // expected-warning {{extra qual}}
185 }
186 
187 // dr312: dup 616
188 
189 namespace dr313 { // dr313: dup 299 c++11
190   struct A { operator int() const; };
191   int *p = new int[A()];
192 #if __cplusplus < 201103L
193   // FIXME: should this be available in c++98 mode? expected-error@-2 {{extension}}
194 #endif
195 }
196 
197 namespace dr314 { // FIXME 314: dup 1710
198   template<typename T> struct A {
199     template<typename U> struct B {};
200   };
201   template<typename T> struct C : public A<T>::template B<T> {
202     C() : A<T>::template B<T>() {}
203   };
204 }
205 
206 // dr315: na
207 // dr316: sup 1004
208 
209 namespace dr317 { // dr317: 3.5
210   void f() {} // expected-note {{previous}}
211   inline void f(); // expected-error {{inline declaration of 'f' follows non-inline definition}}
212 
213   int g();
214   int n = g();
215   inline int g() { return 0; }
216 
217   int h();
218   int m = h();
219   int h() { return 0; } // expected-note {{previous}}
220   inline int h(); // expected-error {{inline declaration of 'h' follows non-inline definition}}
221 }
222 
223 namespace dr318 { // dr318: sup 1310
224   struct A {};
225   struct A::A a;
226 }
227 
228 namespace dr319 { // dr319: no
229   // FIXME: dup dr389
230   // FIXME: We don't have a diagnostic for a name with linkage
231   //        having a type without linkage.
232   typedef struct {
233     int i;
234   } *ps;
235   extern "C" void f(ps);
236   void g(ps); // FIXME: ill-formed, type 'ps' has no linkage
237 
238   static enum { e } a1;
239   enum { e2 } a2; // FIXME: ill-formed, enum type has no linkage
240 
241   enum { n1 = 1u };
242   typedef int (*pa)[n1];
243   pa parr; // ok, type has linkage despite using 'n1'
244 
245   template<typename> struct X {};
246 
247   void f() {
248     struct A { int n; };
249     extern A a; // FIXME: ill-formed
250     X<A> xa;
251 
252     typedef A B;
253     extern B b; // FIXME: ill-formed
254     X<B> xb;
255 
256     const int n = 1;
257     typedef int (*C)[n];
258     extern C c; // ok
259     X<C> xc;
260   }
261 #if __cplusplus < 201103L
262   // expected-error@-12 {{uses local type 'A'}}
263   // expected-error@-9 {{uses local type 'A'}}
264 #endif
265 }
266 
267 namespace dr320 { // dr320: yes
268 #if __cplusplus >= 201103L
269   struct X {
270     constexpr X() {}
271     constexpr X(const X &x) : copies(x.copies + 1) {}
272     unsigned copies = 0;
273   };
274   constexpr X f(X x) { return x; }
275   constexpr unsigned g(X x) { return x.copies; }
276   static_assert(f(X()).copies == g(X()) + 1, "expected one extra copy for return value");
277 #endif
278 }
279 
280 namespace dr321 { // dr321: dup 557
281   namespace N {
282     template<int> struct A {
283       template<int> struct B;
284     };
285     template<> template<> struct A<0>::B<0>;
286     void f(A<0>::B<0>);
287   }
288   template<> template<> struct N::A<0>::B<0> {};
289 
290   template<typename T> void g(T t) { f(t); }
291   template void g(N::A<0>::B<0>);
292 
293   namespace N {
294     template<typename> struct I { friend bool operator==(const I&, const I&); };
295   }
296   N::I<int> i, j;
297   bool x = i == j;
298 }
299 
300 namespace dr322 { // dr322: yes
301   struct A {
302     template<typename T> operator T&();
303   } a;
304   int &r = static_cast<int&>(a);
305   int &s = a;
306 }
307 
308 // dr323: no
309 
310 namespace dr324 { // dr324: yes
311   struct S { int n : 1; } s; // expected-note 3{{bit-field is declared here}}
312   int &a = s.n; // expected-error {{non-const reference cannot bind to bit-field}}
313   int *b = &s.n; // expected-error {{address of bit-field}}
314   int &c = (s.n = 0); // expected-error {{non-const reference cannot bind to bit-field}}
315   int *d = &(s.n = 0); // expected-error {{address of bit-field}}
316   int &e = true ? s.n : s.n; // expected-error {{non-const reference cannot bind to bit-field}}
317   int *f = &(true ? s.n : s.n); // expected-error {{address of bit-field}}
318   int &g = (void(), s.n); // expected-error {{non-const reference cannot bind to bit-field}}
319   int *h = &(void(), s.n); // expected-error {{address of bit-field}}
320   int *i = &++s.n; // expected-error {{address of bit-field}}
321 }
322 
323 namespace dr326 { // dr326: yes
324   struct S {};
325   int test[__is_trivially_constructible(S, const S&) ? 1 : -1];
326 }
327 
328 namespace dr327 { // dr327: dup 538
329   struct A;
330   class A {};
331 
332   class B;
333   struct B {};
334 }
335 
336 namespace dr328 { // dr328: yes
337   struct A; // expected-note 3{{forward declaration}}
338   struct B { A a; }; // expected-error {{incomplete}}
339   template<typename> struct C { A a; }; // expected-error {{incomplete}}
340   A *p = new A[0]; // expected-error {{incomplete}}
341 }
342 
343 namespace dr329 { // dr329: 3.5
344   struct B {};
345   template<typename T> struct A : B {
346     friend void f(A a) { g(a); }
347     friend void h(A a) { g(a); } // expected-error {{undeclared}}
348     friend void i(B b) {} // expected-error {{redefinition}} expected-note {{previous}}
349   };
350   A<int> a;
351   A<char> b; // expected-note {{instantiation}}
352 
353   void test() {
354     h(a); // expected-note {{instantiation}}
355   }
356 }
357 
358 namespace dr331 { // dr331: yes
359   struct A {
360     A(volatile A&); // expected-note {{candidate}}
361   } const a, b(a); // expected-error {{no matching constructor}}
362 }
363 
364 namespace dr332 { // dr332: dup 577
365   void f(volatile void); // expected-error {{'void' as parameter must not have type qualifiers}}
366   void g(const void); // expected-error {{'void' as parameter must not have type qualifiers}}
367   void h(int n, volatile void); // expected-error {{'void' must be the first and only parameter}}
368 }
369 
370 namespace dr333 { // dr333: yes
371   int n = 0;
372   int f(int(n));
373   int g((int(n)));
374   int h = f(g);
375 }
376 
377 namespace dr334 { // dr334: yes
378   template<typename T> void f() {
379     T x;
380     f((x, 123));
381   }
382   struct S {
383     friend S operator,(S, int);
384     friend void f(S);
385   };
386   template void f<S>();
387 }
388 
389 // dr335: no
390 
391 namespace dr336 { // dr336: yes
392   namespace Pre {
393     template<class T1> class A {
394       template<class T2> class B {
395         template<class T3> void mf1(T3);
396         void mf2();
397       };
398     };
399     template<> template<class X> class A<int>::B {};
400     template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {} // expected-error {{does not match}}
401     template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
402   }
403   namespace Post {
404     template<class T1> class A {
405       template<class T2> class B {
406         template<class T3> void mf1(T3);
407         void mf2();
408       };
409     };
410     template<> template<class X> class A<int>::B {
411       template<class T> void mf1(T);
412     };
413     template<> template<> template<class T> void A<int>::B<double>::mf1(T t) {}
414     // FIXME: This diagnostic isn't very good.
415     template<class Y> template<> void A<Y>::B<double>::mf2() {} // expected-error {{does not refer into a class}}
416   }
417 }
418 
419 namespace dr337 { // dr337: yes
420   template<typename T> void f(T (*)[1]);
421   template<typename T> int &f(...);
422 
423   struct A { virtual ~A() = 0; };
424   int &r = f<A>(0);
425 
426   // FIXME: The language rules here are completely broken. We cannot determine
427   // whether an incomplete type is abstract. See DR1640, which will probably
428   // supersede this one and remove this rule.
429   struct B;
430   int &s = f<B>(0); // expected-error {{of type 'void'}}
431   struct B { virtual ~B() = 0; };
432 }
433 
434 namespace dr339 { // dr339: yes
435   template <int I> struct A { static const int value = I; };
436 
437   char xxx(int);
438   char (&xxx(float))[2];
439 
440   template<class T> A<sizeof(xxx((T)0))> f(T) {} // expected-note {{candidate}}
441 
442   void test() {
443     A<1> a = f(0);
444     A<2> b = f(0.0f);
445     A<3> c = f("foo"); // expected-error {{no matching function}}
446   }
447 
448 
449   char f(int);
450   int f(...);
451 
452   template <class T> struct conv_int {
453     static const bool value = sizeof(f(T())) == 1;
454   };
455 
456   template <class T> bool conv_int2(A<sizeof(f(T()))> p);
457 
458   template<typename T> A<sizeof(f(T()))> make_A();
459 
460   int a[conv_int<char>::value ? 1 : -1];
461   bool b = conv_int2<char>(A<1>());
462   A<1> c = make_A<char>();
463 }
464 
465 namespace dr340 { // dr340: yes
466   struct A { A(int); };
467   struct B { B(A, A, int); };
468   int x, y;
469   B b(A(x), A(y), 3);
470 }
471 
472 namespace dr341 { // dr341: sup 1708
473   namespace A {
474     int n;
475     extern "C" int &dr341_a = n; // expected-note {{previous}} expected-note {{declared with C language linkage here}}
476   }
477   namespace B {
478     extern "C" int &dr341_a = dr341_a; // expected-error {{redefinition}}
479   }
480   extern "C" void dr341_b(); // expected-note {{declared with C language linkage here}}
481 }
482 int dr341_a; // expected-error {{declaration of 'dr341_a' in global scope conflicts with declaration with C language linkage}}
483 int dr341_b; // expected-error {{declaration of 'dr341_b' in global scope conflicts with declaration with C language linkage}}
484 int dr341_c; // expected-note {{declared in global scope here}}
485 int dr341_d; // expected-note {{declared in global scope here}}
486 namespace dr341 {
487   extern "C" int dr341_c; // expected-error {{declaration of 'dr341_c' with C language linkage conflicts with declaration in global scope}}
488   extern "C" void dr341_d(); // expected-error {{declaration of 'dr341_d' with C language linkage conflicts with declaration in global scope}}
489 
490   namespace A { extern "C" int dr341_e; } // expected-note {{previous}}
491   namespace B { extern "C" void dr341_e(); } // expected-error {{redefinition of 'dr341_e' as different kind of symbol}}
492 }
493 
494 // dr342: na
495 
496 namespace dr343 { // FIXME 343: no
497   // FIXME: dup 1710
498   template<typename T> struct A {
499     template<typename U> struct B {};
500   };
501   // FIXME: In these contexts, the 'template' keyword is optional.
502   template<typename T> struct C : public A<T>::B<T> { // expected-error {{use 'template'}}
503     C() : A<T>::B<T>() {} // expected-error {{use 'template'}}
504   };
505 }
506 
507 namespace dr344 { // dr344: dup 1435
508   struct A { inline virtual ~A(); };
509   struct B { friend A::~A(); };
510 }
511 
512 namespace dr345 { // dr345: yes
513   struct A {
514     struct X {};
515     int X; // expected-note {{here}}
516   };
517   struct B {
518     struct X {};
519   };
520   template <class T> void f(T t) { typename T::X x; } // expected-error {{refers to non-type member 'X'}}
521   void f(A a, B b) {
522     f(b);
523     f(a); // expected-note {{instantiation}}
524   }
525 }
526 
527 // dr346: na
528 
529 namespace dr347 { // dr347: yes
530   struct base {
531     struct nested;
532     static int n;
533     static void f();
534     void g();
535   };
536 
537   struct derived : base {};
538 
539   struct derived::nested {}; // expected-error {{no struct named 'nested'}}
540   int derived::n; // expected-error {{no member named 'n'}}
541   void derived::f() {} // expected-error {{does not match any}}
542   void derived::g() {} // expected-error {{does not match any}}
543 }
544 
545 // dr348: na
546 
547 namespace dr349 { // dr349: no
548   struct A {
549     template <class T> operator T ***() {
550       int ***p = 0;
551       return p; // expected-error {{cannot initialize return object of type 'const int ***' with an lvalue of type 'int ***'}}
552     }
553   };
554 
555   // FIXME: This is valid.
556   A a;
557   const int *const *const *p1 = a; // expected-note {{in instantiation of}}
558 
559   struct B {
560     template <class T> operator T ***() {
561       const int ***p = 0;
562       return p;
563     }
564   };
565 
566   // FIXME: This is invalid.
567   B b;
568   const int *const *const *p2 = b;
569 }
570 
571 // dr351: na
572 
573 namespace dr352 { // dr352: yes
574   namespace example1 {
575     namespace A {
576       enum E {};
577       template<typename R, typename A> void foo(E, R (*)(A)); // expected-note 2{{couldn't infer template argument 'R'}}
578     }
579 
580     template<typename T> void arg(T);
581     template<typename T> int arg(T) = delete; // expected-note {{here}} expected-error 0-1{{extension}}
582 
583     void f(A::E e) {
584       foo(e, &arg); // expected-error {{no matching function}}
585 
586       using A::foo;
587       foo<int, int>(e, &arg); // expected-error {{deleted}}
588     }
589 
590     int arg(int);
591 
592     void g(A::E e) {
593       foo(e, &arg); // expected-error {{no matching function}}
594 
595       using A::foo;
596       foo<int, int>(e, &arg); // ok, uses non-template
597     }
598   }
599 
600   namespace contexts {
601     template<int I> void f1(int (&)[I]);
602     template<int I> void f2(int (&)[I+1]); // expected-note {{couldn't infer}}
603     template<int I> void f3(int (&)[I+1], int (&)[I]);
604     void f() {
605       int a[4];
606       int b[3];
607       f1(a);
608       f2(a); // expected-error {{no matching function}}
609       f3(a, b);
610     }
611 
612     template<int I> struct S {};
613     template<int I> void g1(S<I>);
614     template<int I> void g2(S<I+1>); // expected-note {{couldn't infer}}
615     template<int I> void g3(S<I+1>, S<I>);
616     void g() {
617       S<4> a;
618       S<3> b;
619       g1(a);
620       g2(a); // expected-error {{no matching function}}
621       g3(a, b);
622     }
623 
624     template<typename T> void h1(T = 0); // expected-note {{couldn't infer}}
625     template<typename T> void h2(T, T = 0);
626     void h() {
627       h1(); // expected-error {{no matching function}}
628       h1(0);
629       h1<int>();
630       h2(0);
631     }
632 
633     template<typename T> int tmpl(T);
634     template<typename R, typename A> void i1(R (*)(A)); // expected-note 3{{couldn't infer}}
635     template<typename R, typename A> void i2(R, A, R (*)(A)); // expected-note {{not viable}}
636     void i() {
637       extern int single(int);
638       i1(single);
639       i2(0, 0, single);
640 
641       extern int ambig(float), ambig(int);
642       i1(ambig); // expected-error {{no matching function}}
643       i2(0, 0, ambig);
644 
645       extern void no_match(float), no_match(int);
646       i1(no_match); // expected-error {{no matching function}}
647       i2(0, 0, no_match); // expected-error {{no matching function}}
648 
649       i1(tmpl); // expected-error {{no matching function}}
650       i2(0, 0, tmpl);
651     }
652   }
653 
654   template<typename T> struct is_int;
655   template<> struct is_int<int> {};
656 
657   namespace example2 {
658     template<typename T> int f(T (*p)(T)) { is_int<T>(); }
659     int g(int);
660     int g(char);
661     int i = f(g);
662   }
663 
664   namespace example3 {
665     template<typename T> int f(T, T (*p)(T)) { is_int<T>(); }
666     int g(int);
667     char g(char);
668     int i = f(1, g);
669   }
670 
671   namespace example4 {
672     template <class T> int f(T, T (*p)(T)) { is_int<T>(); }
673     char g(char);
674     template <class T> T g(T);
675     int i = f(1, g);
676   }
677 
678   namespace example5 {
679     template<int I> class A {};
680     template<int I> void g(A<I+1>); // expected-note {{couldn't infer}}
681     template<int I> void f(A<I>, A<I+1>);
682     void h(A<1> a1, A<2> a2) {
683       g(a1); // expected-error {{no matching function}}
684       g<0>(a1);
685       f(a1, a2);
686     }
687   }
688 }
689 
690 // dr353 needs an IRGen test.
691 
692 namespace dr354 { // dr354: yes c++11
693   // FIXME: Should we allow this in C++98 too?
694   struct S {};
695 
696   template<int*> struct ptr {}; // expected-note 0-4{{here}}
697   ptr<0> p0;
698   ptr<(int*)0> p1;
699   ptr<(float*)0> p2;
700   ptr<(int S::*)0> p3;
701 #if __cplusplus < 201103L
702   // expected-error@-5 {{does not refer to any decl}}
703   // expected-error@-5 {{does not refer to any decl}}
704   // expected-error@-5 {{does not refer to any decl}}
705   // expected-error@-5 {{does not refer to any decl}}
706 #elif __cplusplus <= 201402L
707   // expected-error@-10 {{must be cast}}
708   // ok
709   // expected-error@-10 {{does not match}}
710   // expected-error@-10 {{does not match}}
711 #else
712   // expected-error@-15 {{conversion from 'int' to 'int *' is not allowed}}
713   // ok
714   // expected-error@-15 {{'float *' is not implicitly convertible to 'int *'}}
715   // expected-error@-15 {{'int dr354::S::*' is not implicitly convertible to 'int *'}}
716 #endif
717 
718   template<int*> int both();
719   template<int> int both();
720   int b0 = both<0>();
721   int b1 = both<(int*)0>();
722 #if __cplusplus < 201103L
723   // expected-error@-2 {{no matching function}}
724   // expected-note@-6 {{candidate}}
725   // expected-note@-6 {{candidate}}
726 #endif
727 
728   template<int S::*> struct ptr_mem {}; // expected-note 0-4{{here}}
729   ptr_mem<0> m0;
730   ptr_mem<(int S::*)0> m1;
731   ptr_mem<(float S::*)0> m2;
732   ptr_mem<(int *)0> m3;
733 #if __cplusplus < 201103L
734   // expected-error@-5 {{cannot be converted}}
735   // expected-error@-5 {{is not a pointer to member constant}}
736   // expected-error@-5 {{cannot be converted}}
737   // expected-error@-5 {{cannot be converted}}
738 #elif __cplusplus <= 201402L
739   // expected-error@-10 {{must be cast}}
740   // ok
741   // expected-error@-10 {{does not match}}
742   // expected-error@-10 {{does not match}}
743 #else
744   // expected-error@-15 {{conversion from 'int' to 'int dr354::S::*' is not allowed}}
745   // ok
746   // expected-error@-15 {{'float dr354::S::*' is not implicitly convertible to 'int dr354::S::*'}}
747   // expected-error@-15 {{'int *' is not implicitly convertible to 'int dr354::S::*'}}
748 #endif
749 }
750 
751 struct dr355_S; // dr355: yes
752 struct ::dr355_S {}; // expected-warning {{extra qualification}}
753 namespace dr355 { struct ::dr355_S s; }
754 
755 // dr356: na
756 
757 namespace dr357 { // dr357: yes
758   template<typename T> struct A {
759     void f() const; // expected-note {{const qualified}}
760   };
761   template<typename T> void A<T>::f() {} // expected-error {{does not match}}
762 
763   struct B {
764     template<typename T> void f();
765   };
766   template<typename T> void B::f() const {} // expected-error {{does not match}}
767 }
768 
769 namespace dr358 { // dr358: yes
770   extern "C" void dr358_f();
771   namespace N {
772     int var;
773     extern "C" void dr358_f() { var = 10; }
774   }
775 }
776 
777 namespace dr359 { // dr359: yes
778   // Note, the example in the DR is wrong; it doesn't contain an anonymous
779   // union.
780   struct E {
781     union {
782       struct {
783         int x;
784       } s;
785     } v;
786 
787     union {
788       struct { // expected-error {{extension}}
789         int x;
790       } s;
791 
792       struct S { // expected-error {{types cannot be declared in an anonymous union}}
793         int x;
794       } t;
795 
796       union { // expected-error {{extension}}
797         int u;
798       };
799     };
800   };
801 }
802 
803 // dr362: na
804 // dr363: na
805 
806 namespace dr364 { // dr364: yes
807   struct S {
808     static void f(int);
809     void f(char);
810   };
811 
812   void g() {
813     S::f('a'); // expected-error {{call to non-static}}
814     S::f(0);
815   }
816 }
817 
818 #if "foo" // expected-error {{invalid token}} dr366: yes
819 #endif
820 
821 namespace dr367 { // dr367: yes
822   // FIXME: These diagnostics are terrible. Don't diagnose an ill-formed global
823   // array as being a VLA!
824   int a[true ? throw 0 : 4]; // expected-error 2{{variable length array}}
825   int b[true ? 4 : throw 0];
826   int c[true ? *new int : 4]; // expected-error 2{{variable length array}}
827   int d[true ? 4 : *new int];
828 #if __cplusplus < 201103L
829   // expected-error@-4 {{variable length array}} expected-error@-4 {{constant expression}}
830   // expected-error@-3 {{variable length array}} expected-error@-3 {{constant expression}}
831 #endif
832 }
833 
834 namespace dr368 { // dr368: yes
835   template<typename T, T> struct S {}; // expected-note {{here}}
836   template<typename T> int f(S<T, T()> *); // expected-error {{function type}}
837   //template<typename T> int g(S<T, (T())> *); // FIXME: crashes clang
838   template<typename T> int g(S<T, true ? T() : T()> *); // expected-note {{cannot have type 'dr368::X'}}
839   struct X {};
840   int n = g<X>(0); // expected-error {{no matching}}
841 }
842 
843 // dr370: na
844 
845 namespace dr372 { // dr372: no
846   namespace example1 {
847     template<typename T> struct X {
848     protected:
849       typedef T Type; // expected-note 2{{protected}}
850     };
851     template<typename T> struct Y {};
852 
853     // FIXME: These two are valid; deriving from T1<T> gives Z1 access to
854     // the protected member T1<T>::Type.
855     template<typename T,
856              template<typename> class T1,
857              template<typename> class T2> struct Z1 :
858       T1<T>,
859       T2<typename T1<T>::Type> {}; // expected-error {{protected}}
860 
861     template<typename T,
862              template<typename> class T1,
863              template<typename> class T2> struct Z2 :
864       T2<typename T1<T>::Type>, // expected-error {{protected}}
865       T1<T> {};
866 
867     Z1<int, X, Y> z1; // expected-note {{instantiation of}}
868     Z2<int, X, Y> z2; // expected-note {{instantiation of}}
869   }
870 
871   namespace example2 {
872     struct X {
873     private:
874       typedef int Type; // expected-note {{private}}
875     };
876     template<typename T> struct A {
877       typename T::Type t; // expected-error {{private}}
878     };
879     A<X> ax; // expected-note {{instantiation of}}
880   }
881 
882   namespace example3 {
883     struct A {
884     protected:
885       typedef int N; // expected-note 2{{protected}}
886     };
887 
888     template<typename T> struct B {};
889     template<typename U> struct C : U, B<typename U::N> {}; // expected-error {{protected}}
890     template<typename U> struct D : B<typename U::N>, U {}; // expected-error {{protected}}
891 
892     C<A> x; // expected-note {{instantiation of}}
893     D<A> y; // expected-note {{instantiation of}}
894   }
895 
896   namespace example4 {
897     class A {
898       class B {};
899       friend class X;
900     };
901 
902     struct X : A::B {
903       A::B mx;
904       class Y {
905         A::B my;
906       };
907     };
908   }
909 }
910 
911 namespace dr373 { // dr373: no
912   // FIXME: This is valid.
913   namespace X { int dr373; } // expected-note 2{{here}}
914   struct dr373 { // expected-note {{here}}
915     void f() {
916       using namespace dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
917       int k = dr373; // expected-error {{does not refer to a value}}
918 
919       namespace Y = dr373::X; // expected-error {{no namespace named 'X' in 'dr373::dr373'}}
920       k = Y::dr373;
921     }
922   };
923 }
924 
925 namespace dr374 { // dr374: yes c++11
926   namespace N {
927     template<typename T> void f();
928     template<typename T> struct A { void f(); };
929   }
930   template<> void N::f<char>() {}
931   template<> void N::A<char>::f() {}
932   template<> struct N::A<int> {};
933 #if __cplusplus < 201103L
934   // expected-error@-4 {{extension}} expected-note@-7 {{here}}
935   // expected-error@-4 {{extension}} expected-note@-7 {{here}}
936   // expected-error@-4 {{extension}} expected-note@-8 {{here}}
937 #endif
938 }
939 
940 // dr375: dup 345
941 // dr376: na
942 
943 namespace dr377 { // dr377: yes
944   enum E { // expected-error {{enumeration values exceed range of largest integer}}
945     a = -__LONG_LONG_MAX__ - 1, // expected-error 0-1{{extension}}
946     b = 2 * (unsigned long long)__LONG_LONG_MAX__ // expected-error 0-2{{extension}}
947   };
948 }
949 
950 // dr378: dup 276
951 // dr379: na
952 
953 namespace dr381 { // dr381: yes
954   struct A {
955     int a;
956   };
957   struct B : virtual A {};
958   struct C : B {};
959   struct D : B {};
960   struct E : public C, public D {};
961   struct F : public A {};
962   void f() {
963     E e;
964     e.B::a = 0; // expected-error {{ambiguous conversion}}
965     F f;
966     f.A::a = 1;
967   }
968 }
969 
970 namespace dr382 { // dr382: yes c++11
971   // FIXME: Should we allow this in C++98 mode?
972   struct A { typedef int T; };
973   typename A::T t;
974   typename dr382::A a;
975 #if __cplusplus < 201103L
976   // expected-error@-3 {{occurs outside of a template}}
977   // expected-error@-3 {{occurs outside of a template}}
978 #endif
979   typename A b; // expected-error {{expected a qualified name}}
980 }
981 
982 namespace dr383 { // dr383: yes
983   struct A { A &operator=(const A&); };
984   struct B { ~B(); };
985   union C { C &operator=(const C&); };
986   union D { ~D(); };
987   int check[(__is_pod(A) || __is_pod(B) || __is_pod(C) || __is_pod(D)) ? -1 : 1];
988 }
989 
990 namespace dr384 { // dr384: yes
991   namespace N1 {
992     template<typename T> struct Base {};
993     template<typename T> struct X {
994       struct Y : public Base<T> {
995         Y operator+(int) const;
996       };
997       Y f(unsigned i) { return Y() + i; }
998     };
999   }
1000 
1001   namespace N2 {
1002     struct Z {};
1003     template<typename T> int *operator+(T, unsigned);
1004   }
1005 
1006   int main() {
1007     N1::X<N2::Z> v;
1008     v.f(0);
1009   }
1010 }
1011 
1012 namespace dr385 { // dr385: yes
1013   struct A { protected: void f(); };
1014   struct B : A { using A::f; };
1015   struct C : A { void g(B b) { b.f(); } };
1016   void h(B b) { b.f(); }
1017 
1018   struct D { int n; }; // expected-note {{member}}
1019   struct E : protected D {}; // expected-note 2{{protected}}
1020   struct F : E { friend int i(E); };
1021   int i(E e) { return e.n; } // expected-error {{protected base}} expected-error {{protected member}}
1022 }
1023 
1024 namespace dr387 { // dr387: yes
1025   namespace old {
1026     template<typename T> class number {
1027       number(int); // expected-note 2{{here}}
1028       friend number gcd(number &x, number &y) {}
1029     };
1030 
1031     void g() {
1032       number<double> a(3), b(4); // expected-error 2{{private}}
1033       a = gcd(a, b);
1034       b = gcd(3, 4); // expected-error {{undeclared}}
1035     }
1036   }
1037 
1038   namespace newer {
1039     template <typename T> class number {
1040     public:
1041       number(int);
1042       friend number gcd(number x, number y) { return 0; }
1043     };
1044 
1045     void g() {
1046       number<double> a(3), b(4);
1047       a = gcd(a, b);
1048       b = gcd(3, 4); // expected-error {{undeclared}}
1049     }
1050   }
1051 }
1052 
1053 // FIXME: dr388 needs codegen test
1054 
1055 namespace dr389 { // dr389: no
1056   struct S {
1057     typedef struct {} A;
1058     typedef enum {} B;
1059     typedef struct {} const C; // expected-note 0-2{{here}}
1060     typedef enum {} const D; // expected-note 0-1{{here}}
1061   };
1062   template<typename> struct T {};
1063 
1064   struct WithLinkage1 {};
1065   enum WithLinkage2 {};
1066   typedef struct {} *WithLinkage3a, WithLinkage3b;
1067   typedef enum {} WithLinkage4a, *WithLinkage4b;
1068   typedef S::A WithLinkage5;
1069   typedef const S::B WithLinkage6;
1070   typedef int WithLinkage7;
1071   typedef void (*WithLinkage8)(WithLinkage2 WithLinkage1::*, WithLinkage5 *);
1072   typedef T<WithLinkage5> WithLinkage9;
1073 
1074   typedef struct {} *WithoutLinkage1; // expected-note 0-1{{here}}
1075   typedef enum {} const WithoutLinkage2; // expected-note 0-1{{here}}
1076   // These two types don't have linkage even though they are externally visible
1077   // and the ODR requires them to be merged across TUs.
1078   typedef S::C WithoutLinkage3;
1079   typedef S::D WithoutLinkage4;
1080   typedef void (*WithoutLinkage5)(int (WithoutLinkage3::*)(char));
1081 
1082 #if __cplusplus >= 201103L
1083   // This has linkage even though its template argument does not.
1084   // FIXME: This is probably a defect.
1085   typedef T<WithoutLinkage1> WithLinkage10;
1086 #else
1087   typedef int WithLinkage10; // dummy
1088 
1089   typedef T<WithLinkage1> GoodArg1;
1090   typedef T<WithLinkage2> GoodArg2;
1091   typedef T<WithLinkage3a> GoodArg3a;
1092   typedef T<WithLinkage3b> GoodArg3b;
1093   typedef T<WithLinkage4a> GoodArg4a;
1094   typedef T<WithLinkage4b> GoodArg4b;
1095   typedef T<WithLinkage5> GoodArg5;
1096   typedef T<WithLinkage6> GoodArg6;
1097   typedef T<WithLinkage7> GoodArg7;
1098   typedef T<WithLinkage8> GoodArg8;
1099   typedef T<WithLinkage9> GoodArg9;
1100 
1101   typedef T<WithoutLinkage1> BadArg1; // expected-error{{template argument uses}}
1102   typedef T<WithoutLinkage2> BadArg2; // expected-error{{template argument uses}}
1103   typedef T<WithoutLinkage3> BadArg3; // expected-error{{template argument uses}}
1104   typedef T<WithoutLinkage4> BadArg4; // expected-error{{template argument uses}}
1105   typedef T<WithoutLinkage5> BadArg5; // expected-error{{template argument uses}}
1106 #endif
1107 
1108   extern WithLinkage1 withLinkage1;
1109   extern WithLinkage2 withLinkage2;
1110   extern WithLinkage3a withLinkage3a;
1111   extern WithLinkage3b withLinkage3b;
1112   extern WithLinkage4a withLinkage4a;
1113   extern WithLinkage4b withLinkage4b;
1114   extern WithLinkage5 withLinkage5;
1115   extern WithLinkage6 withLinkage6;
1116   extern WithLinkage7 withLinkage7;
1117   extern WithLinkage8 withLinkage8;
1118   extern WithLinkage9 withLinkage9;
1119   extern WithLinkage10 withLinkage10;
1120 
1121   // FIXME: These are all ill-formed.
1122   extern WithoutLinkage1 withoutLinkage1;
1123   extern WithoutLinkage2 withoutLinkage2;
1124   extern WithoutLinkage3 withoutLinkage3;
1125   extern WithoutLinkage4 withoutLinkage4;
1126   extern WithoutLinkage5 withoutLinkage5;
1127 
1128   // OK, extern "C".
1129   extern "C" {
1130     extern WithoutLinkage1 dr389_withoutLinkage1;
1131     extern WithoutLinkage2 dr389_withoutLinkage2;
1132     extern WithoutLinkage3 dr389_withoutLinkage3;
1133     extern WithoutLinkage4 dr389_withoutLinkage4;
1134     extern WithoutLinkage5 dr389_withoutLinkage5;
1135   }
1136 
1137   // OK, defined.
1138   WithoutLinkage1 withoutLinkageDef1;
1139   WithoutLinkage2 withoutLinkageDef2 = WithoutLinkage2();
1140   WithoutLinkage3 withoutLinkageDef3 = {};
1141   WithoutLinkage4 withoutLinkageDef4 = WithoutLinkage4();
1142   WithoutLinkage5 withoutLinkageDef5;
1143 
1144   void use(const void *);
1145   void use_all() {
1146     use(&withLinkage1); use(&withLinkage2); use(&withLinkage3a); use(&withLinkage3b);
1147     use(&withLinkage4a); use(&withLinkage4b); use(&withLinkage5); use(&withLinkage6);
1148     use(&withLinkage7); use(&withLinkage8); use(&withLinkage9); use(&withLinkage10);
1149 
1150     use(&withoutLinkage1); use(&withoutLinkage2); use(&withoutLinkage3);
1151     use(&withoutLinkage4); use(&withoutLinkage5);
1152 
1153     use(&dr389_withoutLinkage1); use(&dr389_withoutLinkage2);
1154     use(&dr389_withoutLinkage3); use(&dr389_withoutLinkage4);
1155     use(&dr389_withoutLinkage5);
1156 
1157     use(&withoutLinkageDef1); use(&withoutLinkageDef2); use(&withoutLinkageDef3);
1158     use(&withoutLinkageDef4); use(&withoutLinkageDef5);
1159   }
1160 
1161   void local() {
1162     // FIXME: This is ill-formed.
1163     extern WithoutLinkage1 withoutLinkageLocal;
1164   }
1165 }
1166 
1167 namespace dr390 { // dr390: yes
1168   template<typename T>
1169   struct A {
1170     A() { f(); } // expected-warning {{call to pure virt}}
1171     virtual void f() = 0; // expected-note {{here}}
1172     virtual ~A() = 0;
1173   };
1174   template<typename T> A<T>::~A() { T::error; } // expected-error {{cannot be used prior to}}
1175   template<typename T> void A<T>::f() { T::error; } // ok, not odr-used
1176   struct B : A<int> { // expected-note 2{{in instantiation of}}
1177     void f() {}
1178   } b;
1179 }
1180 
1181 namespace dr391 { // dr391: yes c++11
1182   // FIXME: Should this apply to C++98 too?
1183   class A { A(const A&); }; // expected-note 0-1{{here}}
1184   A fa();
1185   const A &a = fa();
1186 #if __cplusplus < 201103L
1187   // expected-error@-2 {{C++98 requires an accessible copy constructor}}
1188 #endif
1189 
1190   struct B { B(const B&) = delete; }; // expected-error 0-1{{extension}} expected-note 0-1{{here}}
1191   B fb();
1192   const B &b = fb();
1193 #if __cplusplus < 201103L
1194   // expected-error@-2 {{deleted}}
1195 #endif
1196 
1197   template<typename T>
1198   struct C {
1199     C(const C&) { T::error; }
1200   };
1201   C<int> fc();
1202   const C<int> &c = fc();
1203 }
1204 
1205 // dr392 FIXME write codegen test
1206 // dr394: na
1207 
1208 namespace dr395 { // dr395: yes
1209   struct S {
1210     template <typename T, int N>(&operator T())[N]; // expected-error {{cannot specify any part of a return type}}
1211     template <typename T, int N> operator(T (&)[N])(); // expected-error {{expected ')'}} expected-note {{to match this '('}} expected-error +{{}}
1212     template <typename T> operator T *() const { return 0; }
1213     template <typename T, typename U> operator T U::*() const { return 0; }
1214     template <typename T, typename U> operator T (U::*)()() const { return 0; } // expected-error +{{}}
1215   };
1216 
1217   struct null1_t {
1218     template <class T, class U> struct ptr_mem_fun_t {
1219       typedef T (U::*type)();
1220     };
1221 
1222     template <class T, class U>
1223     operator typename ptr_mem_fun_t<T, U>::type() const { // expected-note {{couldn't infer}}
1224       return 0;
1225     }
1226   } null1;
1227   int (S::*p)() = null1; // expected-error {{no viable conversion}}
1228 
1229   template <typename T> using id = T; // expected-error 0-1{{extension}}
1230 
1231   struct T {
1232     template <typename T, int N> operator id<T[N]> &();
1233     template <typename T, typename U> operator id<T (U::*)()>() const;
1234   };
1235 
1236   struct null2_t {
1237     template<class T, class U> using ptr_mem_fun_t = T (U::*)(); // expected-error 0-1{{extension}}
1238     template<class T, class U> operator ptr_mem_fun_t<T, U>() const { return 0; };
1239   } null2;
1240   int (S::*q)() = null2;
1241 }
1242 
1243 namespace dr396 { // dr396: yes
1244   void f() {
1245     auto int a(); // expected-error {{storage class on function}}
1246     int (i); // expected-note {{previous}}
1247     auto int (i); // expected-error {{redefinition}}
1248 #if __cplusplus >= 201103L
1249   // expected-error@-4 {{'auto' storage class}} expected-error@-2 {{'auto' storage class}}
1250 #endif
1251   }
1252 }
1253 
1254 // dr397: sup 1823
1255 
1256 namespace dr398 { // dr398: yes
1257   namespace example1 {
1258     struct S {
1259       static int const I = 42;
1260     };
1261     template <int N> struct X {};
1262     template <typename T> void f(X<T::I> *) {}
1263     template <typename T> void f(X<T::J> *) {}
1264     void foo() { f<S>(0); }
1265   }
1266 
1267   namespace example2 {
1268     template <int I> struct X {};
1269     template <template <class T> class> struct Z {};
1270     template <class T> void f(typename T::Y *) {} // expected-note 2{{substitution failure}}
1271     template <class T> void g(X<T::N> *) {} // expected-note {{substitution failure}}
1272     template <class T> void h(Z<T::template TT> *) {} // expected-note {{substitution failure}}
1273     struct A {};
1274     struct B {
1275       int Y;
1276     };
1277     struct C {
1278       typedef int N;
1279     };
1280     struct D {
1281       typedef int TT;
1282     };
1283 
1284     void test() {
1285       f<A>(0); // expected-error {{no matching function}}
1286       f<B>(0); // expected-error {{no matching function}}
1287       g<C>(0); // expected-error {{no matching function}}
1288       h<D>(0); // expected-error {{no matching function}}
1289     }
1290   }
1291 }
1292