1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++1z %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 
6 // FIXME: This is included to avoid a diagnostic with no source location
7 // pointing at the implicit operator new. We can't match such a diagnostic
8 // with -verify.
9 __extension__ typedef __SIZE_TYPE__ size_t;
10 void *operator new(size_t); // expected-error 0-1{{missing exception spec}} expected-note{{candidate}}
11 
12 namespace dr500 { // dr500: dup 372
13   class D;
14   class A {
15     class B;
16     class C;
17     friend class D;
18   };
19   class A::B {};
20   class A::C : public A::B {};
21   class D : public A::B {};
22 }
23 
24 namespace dr501 { // dr501: yes
25   struct A {
f()26     friend void f() {}
gdr501::A27     void g() {
28       void (*p)() = &f; // expected-error {{undeclared identifier}}
29     }
30   };
31 }
32 
33 namespace dr502 { // dr502: yes
34   struct Q {};
35   template<typename T> struct A {
36     enum E { e = 1 };
q1dr502::A37     void q1() { f(e); }
q2dr502::A38     void q2() { Q arr[sizeof(E)]; f(arr); }
q3dr502::A39     void q3() { Q arr[e]; f(arr); }
sanitydr502::A40     void sanity() { Q arr[1]; f(arr); } // expected-error {{undeclared identifier 'f'}}
41   };
42   int f(A<int>::E);
43   template<int N> int f(Q (&)[N]);
44   template struct A<int>;
45 }
46 
47 namespace dr505 { // dr505: yes
48   const char *exts = "\e\(\{\[\%"; // expected-error 5{{use of non-standard escape}}
49   const char *unknown = "\Q"; // expected-error {{unknown escape sequence}}
50 }
51 
52 namespace dr506 { // dr506: yes
53   struct NonPod { ~NonPod(); };
54   void f(...);
g(NonPod np)55   void g(NonPod np) { f(np); } // expected-error {{cannot pass}}
56 }
57 
58 // FIXME: Add tests here once DR260 is resolved.
59 // dr507: dup 260
60 
61 // dr508: na
62 // dr509: na
63 // dr510: na
64 
65 namespace dr512 { // dr512: yes
66   struct A {
67     A(int);
68   };
69   union U { A a; };
70 #if __cplusplus < 201103L
71   // expected-error@-2 {{has a non-trivial constructor}}
72   // expected-note@-6 {{no default constructor}}
73   // expected-note@-6 {{suppressed by user-declared constructor}}
74 #endif
75 }
76 
77 // dr513: na
78 
79 namespace dr514 { // dr514: yes
80   namespace A { extern int x, y; }
81   int A::x = y;
82 }
83 
84 namespace dr515 { // dr515: sup 1017
85   // FIXME: dr1017 reverses the wording of dr515, but the current draft has
86   // dr515's wording, with a different fix for dr1017.
87 
88   struct X { int n; };
89   template<typename T> struct Y : T {
fdr515::Y90     int f() { return X::n; }
91   };
92   int k = Y<X>().f();
93 
94   struct A { int a; };
fdr515::B95   struct B { void f() { int k = sizeof(A::a); } };
96 #if __cplusplus < 201103L
97   // expected-error@-2 {{invalid use of non-static data member}}
98 #endif
99 }
100 
101 // dr516: na
102 
103 namespace dr517 { // dr517: no
104   // This is NDR, but we should diagnose it anyway.
105   template<typename T> struct S {};
106   template<typename T> int v = 0; // expected-error 0-1{{extension}}
107 
108   template struct S<int*>;
109   template int v<int*>;
110 
111   S<char&> s;
112   int k = v<char&>;
113 
114   // FIXME: These are both ill-formed.
115   template<typename T> struct S<T*> {};
116   template<typename T> int v<T*> = 0; // expected-error 0-1{{extension}}
117 
118   // FIXME: These are both ill-formed.
119   template<typename T> struct S<T&> {};
120   template<typename T> int v<T&> = 0; // expected-error 0-1{{extension}}
121 }
122 
123 namespace dr518 { // dr518: yes c++11
124   enum E { e, };
125 #if __cplusplus < 201103L
126   // expected-error@-2 {{C++11 extension}}
127 #endif
128 }
129 
130 namespace dr519 { // dr519: yes
131 // FIXME: Add a codegen test.
132 #if __cplusplus >= 201103L
133 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
134   int test[fold((int*)(void*)0) ? -1 : 1];
135 #undef fold
136 #endif
137 }
138 
139 // dr520: na
140 
141 // dr521: no
142 // FIXME: The wording here is broken. It's not reasonable to expect a
143 // diagnostic here. Once the relevant DR gets a number, mark this as a dup.
144 
145 namespace dr522 { // dr522: yes
146   struct S {};
147   template<typename T> void b1(volatile T &);
148   template<typename T> void b2(volatile T * const *);
149   template<typename T> void b2(volatile T * const S::*);
150   template<typename T> void b2(volatile T * const S::* const *);
151   // FIXME: This diagnostic isn't very good. The problem is not substitution failure.
152   template<typename T> void b2a(volatile T *S::* const *); // expected-note {{substitution failure}}
153 
154   template<typename T> struct Base {};
155   struct Derived : Base<int> {};
156   template<typename T> void b3(Base<T>);
157   template<typename T> void b3(Base<T> *);
158 
test(int n,const int cn,int ** p,int * S::* pm)159   void test(int n, const int cn, int **p, int *S::*pm) {
160     int *a[3], *S::*am[3];
161     const Derived cd = Derived();
162     Derived d[3];
163 
164     b1(n);
165     b1(cn);
166     b2(p);
167     b2(pm);
168     b2(a);
169     b2(am);
170     b2a(am); // expected-error {{no matching function}}
171     b3(d);
172     b3(cd);
173   }
174 }
175 
176 namespace dr524 { // dr524: yes
f(T a,T b)177   template<typename T> void f(T a, T b) { operator+(a, b); } // expected-error {{call}}
178 
179   struct S {};
180   void operator+(S, S);
181   template void f(S, S);
182 
183   namespace N { struct S {}; }
184   void operator+(N::S, N::S); // expected-note {{should be declared}}
185   template void f(N::S, N::S); // expected-note {{instantiation}}
186 }
187 
188 namespace dr525 { // dr525: yes
189   namespace before {
190     // Note, the example was correct prior to the change; instantiation is
191     // required for cases like this:
192     template <class T> struct D { operator T*(); };
g(D<double> ppp)193     void g(D<double> ppp) {
194       delete ppp;
195     }
196   }
197   namespace after {
198     template <class T> struct D { typename T::error e; }; // expected-error {{prior to '::'}}
g(D<double> * ppp)199     void g(D<double> *ppp) {
200       delete ppp; // expected-note {{instantiation of}}
201     }
202   }
203 }
204 
205 namespace dr526 { // dr526: yes
206   template<int> struct S {};
207   template<int N> void f1(S<N> s);
208   template<int N> void f2(S<(N)> s); // expected-note {{couldn't infer}}
209   template<int N> void f3(S<+N> s); // expected-note {{couldn't infer}}
210   template<int N> void g1(int (&)[N]);
211   template<int N> void g2(int (&)[(N)]); // expected-note {{couldn't infer}}
212   template<int N> void g3(int (&)[+N]); // expected-note {{couldn't infer}}
213 
test(int (& a)[3],S<3> s)214   void test(int (&a)[3], S<3> s) {
215     f1(s);
216     f2(s); // expected-error {{no matching}}
217     f3(s); // expected-error {{no matching}}
218     g1(a);
219     g2(a); // expected-error {{no matching}}
220     g3(a); // expected-error {{no matching}}
221   }
222 
223   template<int N> struct X {
224     typedef int type;
225     X<N>::type v1;
226     X<(N)>::type v2; // expected-error {{missing 'typename'}}
227     X<+N>::type v3; // expected-error {{missing 'typename'}}
228   };
229 }
230 
231 namespace dr527 { // dr527: na
232   // This DR is meaningless. It removes a required diagnostic from the case
233   // where a not-externally-visible object is odr-used but not defined, which
234   // requires a diagnostic for a different reason.
235   extern struct { int x; } a; // FIXME: We should reject this, per dr389.
236   static struct { int x; } b;
237   extern "C" struct { int x; } c;
238   namespace { extern struct { int x; } d; }
239   typedef struct { int x; } *P;
240   struct E { static P e; }; // FIXME: We should reject this, per dr389.
241   namespace { struct F { static P f; }; }
242 
243   int ax = a.x, bx = b.x, cx = c.x, dx = d.x, ex = E::e->x, fx = F::f->x;
244 }
245 
246 namespace dr530 { // dr530: yes
247   template<int*> struct S { enum { N = 1 }; };
248   template<void(*)()> struct T { enum { N = 1 }; };
249   int n;
250   void f();
251   int a[S<&n>::N];
252   int b[T<&f>::N];
253 }
254 
255 namespace dr531 { // dr531: partial
256   namespace good {
257     template<typename T> struct A {
fdr531::good::A258       void f(T) { T::error; }
gdr531::good::A259       template<typename U> void g(T, U) { T::error; }
260       struct B { typename T::error error; };
261       template<typename U> struct C { typename T::error error; };
262       static T n;
263     };
264     template<typename T> T A<T>::n = T::error;
265 
f(int)266     template<> void A<int>::f(int) {}
g(int,U)267     template<> template<typename U> void A<int>::g(int, U) {}
268     template<> struct A<int>::B {};
269     template<> template<typename U> struct A<int>::C {};
270     template<> int A<int>::n = 0;
271 
use(A<int> a)272     void use(A<int> a) {
273       a.f(a.n);
274       a.g(0, 0);
275       A<int>::B b;
276       A<int>::C<int> c;
277     }
278 
279     template<> struct A<char> {
280       void f(char);
281       template<typename U> void g(char, U);
282       struct B;
283       template<typename U> struct C;
284       static char n;
285     };
286 
f(char)287     void A<char>::f(char) {}
g(char,U)288     template<typename U> void A<char>::g(char, U) {}
289     struct A<char>::B {};
290     template<typename U> struct A<char>::C {};
291     char A<char>::n = 0;
292   }
293 
294   namespace bad {
295     template<typename T> struct A {
fdr531::bad::A296       void f(T) { T::error; }
gdr531::bad::A297       template<typename U> void g(T, U) { T::error; }
298       struct B { typename T::error error; };
299       template<typename U> struct C { typename T::error error; }; // expected-note {{here}}
300       static T n;
301     };
302     template<typename T> T A<T>::n = T::error;
303 
f(int)304     void A<int>::f(int) {} // expected-error {{requires 'template<>'}}
g(int,U)305     template<typename U> void A<int>::g(int, U) {} // expected-error {{should be empty}}
306     struct A<int>::B {}; // expected-error {{requires 'template<>'}}
307     template<typename U> struct A<int>::C {}; // expected-error {{should be empty}} expected-error {{different kind of symbol}}
308     int A<int>::n = 0; // expected-error {{requires 'template<>'}}
309 
310     template<> struct A<char> { // expected-note 2{{here}}
311       void f(char);
312       template<typename U> void g(char, U);
313       struct B; // expected-note {{here}}
314       template<typename U> struct C;
315       static char n;
316     };
317 
f(char)318     template<> void A<char>::f(char) {} // expected-error {{no function template matches}}
319     // FIXME: This is ill-formed; -pedantic-errors should reject.
g(char,U)320     template<> template<typename U> void A<char>::g(char, U) {} // expected-warning {{extraneous template parameter list}}
321     template<> struct A<char>::B {}; // expected-error {{extraneous 'template<>'}} expected-error {{does not specialize}}
322     // FIXME: This is ill-formed; -pedantic-errors should reject.
323     template<> template<typename U> struct A<char>::C {}; // expected-warning {{extraneous template parameter list}}
324     template<> char A<char>::n = 0; // expected-error {{extraneous 'template<>'}}
325   }
326 
327   namespace nested {
328     template<typename T> struct A {
329       template<typename U> struct B;
330     };
331     template<> template<typename U> struct A<int>::B {
332       void f();
333       void g();
334       template<typename V> void h();
335       template<typename V> void i();
336     };
f()337     template<> template<typename U> void A<int>::B<U>::f() {}
g()338     template<typename U> void A<int>::B<U>::g() {} // expected-error {{should be empty}}
339 
h()340     template<> template<typename U> template<typename V> void A<int>::B<U>::h() {}
i()341     template<typename U> template<typename V> void A<int>::B<U>::i() {} // expected-error {{should be empty}}
342 
f()343     template<> template<> void A<int>::B<int>::f() {}
h()344     template<> template<> template<typename V> void A<int>::B<int>::h() {}
h()345     template<> template<> template<> void A<int>::B<int>::h<int>() {}
346 
f()347     template<> void A<int>::B<char>::f() {} // expected-error {{requires 'template<>'}}
h()348     template<> template<typename V> void A<int>::B<char>::h() {} // expected-error {{should be empty}}
349   }
350 }
351 
352 // PR8130
353 namespace dr532 { // dr532: 3.5
354   struct A { };
355 
356   template<class T> struct B {
357     template<class R> int &operator*(R&);
358   };
359 
360   template<class T, class R> float &operator*(T&, R&);
test()361   void test() {
362     A a;
363     B<A> b;
364     int &ir = b * a;
365   }
366 }
367 
368 // dr533: na
369 
370 namespace dr534 { // dr534: yes
371   struct S {};
372   template<typename T> void operator+(S, T);
373   template<typename T> void operator+<T*>(S, T*) {} // expected-error {{function template partial spec}}
374 }
375 
376 namespace dr535 { // dr535: yes
377   class X { private: X(const X&); };
378   struct A {
379     X x;
380     template<typename T> A(T&);
381   };
382   struct B : A {
383     X y;
384     B(volatile A&);
385   };
386 
387   extern A a1;
388   A a2(a1); // ok, uses constructor template
389 
390   extern volatile B b1;
391   B b2(b1); // ok, uses converting constructor
392 
f()393   void f() { throw a1; }
394 
395 #if __cplusplus >= 201103L
396   struct C {
Cdr535::C397     constexpr C() : n(0) {}
Cdr535::C398     template<typename T> constexpr C(T&t) : n(t.n == 0 ? throw 0 : 0) {}
399     int n;
400   };
c()401   constexpr C c() { return C(); }
402   // ok, copy is elided
403   constexpr C x = c();
404 #endif
405 }
406 
407 // dr537: na
408 // dr538: na
409 
410 // dr539: yes
dr539(const a)411 const dr539( // expected-error {{requires a type specifier}}
412     const a) { // expected-error {{unknown type name 'a'}}
413   const b; // expected-error {{requires a type specifier}}
414   new const; // expected-error {{expected a type}}
415   try {} catch (const n) {} // expected-error {{unknown type name 'n'}}
416   try {} catch (const) {} // expected-error {{expected a type}}
417   if (const n = 0) {} // expected-error {{requires a type specifier}}
418   switch (const n = 0) {} // expected-error {{requires a type specifier}}
419   while (const n = 0) {} // expected-error {{requires a type specifier}}
420   for (const n = 0; // expected-error {{requires a type specifier}}
421        const m = 0; ) {} // expected-error {{requires a type specifier}}
422   sizeof(const); // expected-error {{requires a type specifier}}
423   struct S {
424     const n; // expected-error {{requires a type specifier}}
425     operator const(); // expected-error {{expected a type}}
426   };
427 #if __cplusplus >= 201103L
428   int arr[3];
429   // FIXME: The extra braces here are to avoid the parser getting too
430   // badly confused when recovering here. We should fix this recovery.
431   { for (const n // expected-error {{unknown type name 'n'}} expected-note {{}}
432          : arr) ; {} } // expected-error +{{}}
433   (void) [](const) {}; // expected-error {{requires a type specifier}}
434   (void) [](const n) {}; // expected-error {{unknown type name 'n'}}
435   enum E : const {}; // expected-error {{expected a type}}
436   using T = const; // expected-error {{expected a type}}
437   auto f() -> const; // expected-error {{expected a type}}
438 #endif
439 }
440 
441 namespace dr540 { // dr540: yes
442   typedef int &a;
443   typedef const a &a; // expected-warning {{has no effect}}
444   typedef const int &b;
445   typedef b &b;
446   typedef const a &c; // expected-note {{previous}} expected-warning {{has no effect}}
447   typedef const b &c; // expected-error {{different}} expected-warning {{has no effect}}
448 }
449 
450 namespace dr541 { // dr541: yes
451   template<int> struct X { typedef int type; };
452   template<typename T> struct S {
453     int f(T);
454 
455     int g(int);
456     T g(bool);
457 
458     int h();
459     int h(T);
460 
xdr541::S461     void x() {
462       // These are type-dependent expressions, even though we could
463       // determine that all calls have type 'int'.
464       X<sizeof(f(0))>::type a; // expected-error +{{}}
465       X<sizeof(g(0))>::type b; // expected-error +{{}}
466       X<sizeof(h(0))>::type b; // expected-error +{{}}
467 
468       typename X<sizeof(f(0))>::type a;
469       typename X<sizeof(h(0))>::type b;
470     }
471   };
472 }
473 
474 namespace dr542 { // dr542: yes
475 #if __cplusplus >= 201103L
476   struct A { A() = delete; int n; };
477   A a[32] = {}; // ok, constructor not called
478 
479   struct B {
480     int n;
481   private:
482     B() = default;
483   };
484   B b[32] = {}; // ok, constructor not called
485 #endif
486 }
487 
488 namespace dr543 { // dr543: yes
489   // In C++98+DR543, this is valid because value-initialization doesn't call a
490   // trivial default constructor, so we never notice that defining the
491   // constructor would be ill-formed.
492   //
493   // In C++11+DR543, this is ill-formed, because the default constructor is
494   // deleted, and value-initialization *does* call a deleted default
495   // constructor, even if it is trivial.
496   struct A {
497     const int n;
498   };
499   A a = A();
500 #if __cplusplus >= 201103L
501   // expected-error@-2 {{deleted}}
502   // expected-note@-5 {{would not be initialized}}
503 #endif
504 }
505 
506 namespace dr544 { // dr544: yes
507   int *n;
508 
509   template<class T> struct A { int n; };
510   template<class T> struct B : A<T> { int get(); };
get()511   template<> int B<int>::get() { return n; }
512   int k = B<int>().get();
513 }
514 
515 namespace dr546 { // dr546: yes
516   template<typename T> struct A { void f(); };
517   template struct A<int>;
f()518   template<typename T> void A<T>::f() { T::error; }
519 }
520 
521 namespace dr547 { // dr547: yes
522   template<typename T> struct X;
523   template<typename T> struct X<T() const> {};
f(T C::*)524   template<typename T, typename C> X<T> f(T C::*) { return X<T>(); }
525 
526   struct S { void f() const; };
527   X<void() const> x = f(&S::f);
528 }
529 
530 namespace dr548 { // dr548: dup 482
531   template<typename T> struct S {};
f()532   template<typename T> void f() {}
533   template struct dr548::S<int>;
534   template void dr548::f<int>();
535 }
536 
537 namespace dr551 { // dr551: yes c++11
538   // FIXME: This obviously should apply in C++98 mode too.
f()539   template<typename T> void f() {}
540   template inline void f<int>();
541 #if __cplusplus >= 201103L
542   // expected-error@-2 {{cannot be 'inline'}}
543 #endif
544 
g()545   template<typename T> inline void g() {}
546   template inline void g<int>();
547 #if __cplusplus >= 201103L
548   // expected-error@-2 {{cannot be 'inline'}}
549 #endif
550 
551   template<typename T> struct X {
fdr551::X552     void f() {}
553   };
554   template inline void X<int>::f();
555 #if __cplusplus >= 201103L
556   // expected-error@-2 {{cannot be 'inline'}}
557 #endif
558 }
559 
560 namespace dr552 { // dr552: yes
561   template<typename T, typename T::U> struct X {};
562   struct Y { typedef int U; };
563   X<Y, 0> x;
564 }
565 
566 struct dr553_class {
567   friend void *operator new(size_t, dr553_class);
568 };
569 namespace dr553 {
570   dr553_class c;
571   // Contrary to the apparent intention of the DR, operator new is not actually
572   // looked up with a lookup mechanism that performs ADL; the standard says it
573   // "is looked up in global scope", where it is not visible.
574   void *p = new (c) int; // expected-error {{no matching function}}
575 
576   struct namespace_scope {
577     friend void *operator new(size_t, namespace_scope); // expected-error {{cannot be declared inside a namespace}}
578   };
579 }
580 
581 // dr556: na
582 
583 namespace dr557 { // dr557: yes
584   template<typename T> struct S {
585     friend void f(S<T> *);
586     friend void g(S<S<T> > *);
587   };
x(S<int> * p,S<S<int>> * q)588   void x(S<int> *p, S<S<int> > *q) {
589     f(p);
590     g(q);
591   }
592 }
593 
594 namespace dr558 { // dr558: yes
595   wchar_t a = L'\uD7FF';
596   wchar_t b = L'\xD7FF';
597   wchar_t c = L'\uD800'; // expected-error {{invalid universal character}}
598   wchar_t d = L'\xD800';
599   wchar_t e = L'\uDFFF'; // expected-error {{invalid universal character}}
600   wchar_t f = L'\xDFFF';
601   wchar_t g = L'\uE000';
602   wchar_t h = L'\xE000';
603 }
604 
605 template<typename> struct dr559 { typedef int T; dr559::T u; }; // dr559: yes
606 
607 namespace dr561 { // dr561: yes
608   template<typename T> void f(int);
g(T t)609   template<typename T> void g(T t) {
610     f<T>(t);
611   }
612   namespace {
613     struct S {};
614     template<typename T> static void f(S);
615   }
h(S s)616   void h(S s) {
617     g(s);
618   }
619 }
620 
621 namespace dr564 { // dr564: yes
622   extern "C++" void f(int);
623   void f(int); // ok
624   extern "C++" { extern int n; }
625   int n; // ok
626 }
627 
628 namespace dr565 { // dr565: yes
629   namespace N {
630     template<typename T> int f(T); // expected-note {{target}}
631   }
632   using N::f; // expected-note {{using}}
633   template<typename T> int f(T*);
634   template<typename T> void f(T);
635   template<typename T, int = 0> int f(T); // expected-error 0-1{{extension}}
636   template<typename T> int f(T, int = 0);
637   template<typename T> int f(T); // expected-error {{conflicts with}}
638 }
639 
640 namespace dr566 { // dr566: yes
641 #if __cplusplus >= 201103L
642   int check[int(-3.99) == -3 ? 1 : -1];
643 #endif
644 }
645 
646 // dr567: na
647 
648 namespace dr568 { // dr568: yes c++11
649   // FIXME: This is a DR issue against C++98, so should probably apply there
650   // too.
651   struct x { int y; };
652   class trivial : x {
653     x y;
654   public:
655     int n;
656   };
657   int check_trivial[__is_trivial(trivial) ? 1 : -1];
658 
659   struct std_layout {
660     std_layout();
661     std_layout(const std_layout &);
662     ~std_layout();
663   private:
664     int n;
665   };
666   int check_std_layout[__is_standard_layout(std_layout) ? 1 : -1];
667 
668   struct aggregate {
669     int x;
670     int y;
671     trivial t;
672     std_layout sl;
673   };
674   aggregate aggr = {};
675 
676   void f(...);
g(trivial t)677   void g(trivial t) { f(t); }
678 #if __cplusplus < 201103L
679   // expected-error@-2 {{non-POD}}
680 #endif
681 
jump()682   void jump() {
683     goto x;
684 #if __cplusplus < 201103L
685     // expected-error@-2 {{cannot jump}}
686     // expected-note@+2 {{non-POD}}
687 #endif
688     trivial t;
689   x: ;
690   }
691 }
692 
693 namespace dr569 { // dr569: yes c++11
694   // FIXME: This is a DR issue against C++98, so should probably apply there
695   // too.
696   ;;;;;
697 #if __cplusplus < 201103L
698   // expected-error@-2 {{C++11 extension}}
699 #endif
700 }
701 
702 namespace dr570 { // dr570: dup 633
703   int n;
704   int &r = n; // expected-note {{previous}}
705   int &r = n; // expected-error {{redefinition}}
706 }
707 
708 namespace dr571 { // dr571 unknown
709   // FIXME: Add a codegen test.
710   typedef int &ir;
711   int n;
712   const ir r = n; // expected-warning {{has no effect}} FIXME: Test if this has internal linkage.
713 }
714 
715 namespace dr572 { // dr572: yes
716   enum E { a = 1, b = 2 };
717   int check[a + b == 3 ? 1 : -1];
718 }
719 
720 namespace dr573 { // dr573: no
721   void *a;
722   int *b = reinterpret_cast<int*>(a);
723   void (*c)() = reinterpret_cast<void(*)()>(a);
724   void *d = reinterpret_cast<void*>(c);
725 #if __cplusplus < 201103L
726   // expected-error@-3 {{extension}}
727   // expected-error@-3 {{extension}}
728 #endif
f()729   void f() { delete a; } // expected-error {{cannot delete}}
730   int n = d - a; // expected-error {{arithmetic on pointers to void}}
731   // FIXME: This is ill-formed.
732   template<void*> struct S;
733   template<int*> struct T;
734 }
735 
736 namespace dr574 { // dr574: yes
737   struct A {
738     A &operator=(const A&) const; // expected-note {{does not match because it is const}}
739   };
740   struct B {
741     B &operator=(const B&) volatile; // expected-note {{nearly matches}}
742   };
743 #if __cplusplus >= 201103L
744   struct C {
745     C &operator=(const C&) &; // expected-note {{not viable}} expected-note {{nearly matches}} expected-note {{here}}
746   };
747   struct D {
748     D &operator=(const D&) &&; // expected-note {{not viable}} expected-note {{nearly matches}} expected-note {{here}}
749   };
test(C c,D d)750   void test(C c, D d) {
751     c = c;
752     C() = c; // expected-error {{no viable}}
753     d = d; // expected-error {{no viable}}
754     D() = d;
755   }
756 #endif
757   struct Test {
758     friend A &A::operator=(const A&); // expected-error {{does not match}}
759     friend B &B::operator=(const B&); // expected-error {{does not match}}
760 #if __cplusplus >= 201103L
761     // FIXME: We shouldn't produce the 'cannot overload' diagnostics here.
762     friend C &C::operator=(const C&); // expected-error {{does not match}} expected-error {{cannot overload}}
763     friend D &D::operator=(const D&); // expected-error {{does not match}} expected-error {{cannot overload}}
764 #endif
765   };
766 }
767 
768 namespace dr575 { // dr575: yes
769   template<typename T, typename U = typename T::type> void a(T); void a(...); // expected-error 0-1{{extension}}
770   template<typename T, typename T::type U = 0> void b(T); void b(...); // expected-error 0-1{{extension}}
771   template<typename T, int U = T::value> void c(T); void c(...); // expected-error 0-1{{extension}}
772   template<typename T> void d(T, int = T::value); void d(...); // expected-error {{cannot be used prior to '::'}}
x()773   void x() {
774     a(0);
775     b(0);
776     c(0);
777     d(0); // expected-note {{in instantiation of default function argument}}
778   }
779 
780   template<typename T = int&> void f(T* = 0); // expected-error 0-1{{extension}}
781   template<typename T = int> void f(T = 0); // expected-error 0-1{{extension}}
g()782   void g() { f<>(); }
783 
784   template<typename T> T &h(T *);
785   template<typename T> T *h(T *);
786   void *p = h((void*)0);
787 }
788 
789 namespace dr576 { // dr576: yes
790   typedef void f() {} // expected-error {{function definition declared 'typedef'}}
791   void f(typedef int n); // expected-error {{invalid storage class}}
f(char c)792   void f(char c) { typedef int n; }
793 }
794 
795 namespace dr577 { // dr577: yes
796   typedef void V;
797   typedef const void CV;
798   void a(void);
799   void b(const void); // expected-error {{qualifiers}}
800   void c(V);
801   void d(CV); // expected-error {{qualifiers}}
802   void (*e)(void) = c;
803   void (*f)(const void); // expected-error {{qualifiers}}
804   void (*g)(V) = a;
805   void (*h)(CV); // expected-error {{qualifiers}}
806   template<typename T> void i(T); // expected-note 2{{requires 1 arg}}
807   template<typename T> void j(void (*)(T)); // expected-note 2{{argument may not have 'void' type}}
k()808   void k() {
809     a();
810     c();
811     i<void>(); // expected-error {{no match}}
812     i<const void>(); // expected-error {{no match}}
813     j<void>(0); // expected-error {{no match}}
814     j<const void>(0); // expected-error {{no match}}
815   }
816 }
817 
818 namespace dr580 { // dr580: no
819   class C;
820   struct A { static C c; };
821   struct B { static C c; };
822   class C {
823     C(); // expected-note {{here}}
824     ~C(); // expected-note {{here}}
825 
826     typedef int I; // expected-note {{here}}
827     template<int> struct X;
828     template<int> friend struct Y;
829     template<int> void f();
830     template<int> friend void g();
831     friend struct A;
832   };
833 
834   template<C::I> struct C::X {};
835   template<C::I> struct Y {};
836   template<C::I> struct Z {}; // FIXME: should reject, accepted because C befriends A!
837 
f()838   template<C::I> void C::f() {}
g()839   template<C::I> void g() {}
h()840   template<C::I> void h() {} // expected-error {{private}}
841 
842   C A::c;
843   C B::c; // expected-error 2{{private}}
844 }
845 
846 // dr582: na
847 
848 namespace dr583 { // dr583: no
849   // see n3624
850   int *p;
851   // FIXME: These are all ill-formed.
852   bool b1 = p < 0;
853   bool b2 = p > 0;
854   bool b3 = p <= 0;
855   bool b4 = p >= 0;
856 }
857 
858 // dr584: na
859 
860 namespace dr585 { // dr585: yes
861   template<typename> struct T;
862   struct A {
863     friend T; // expected-error {{requires a type specifier}} expected-error {{can only be classes or functions}}
864     // FIXME: It's not clear whether the standard allows this or what it means,
865     // but the DR585 writeup suggests it as an alternative.
866     template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
867   };
868   template<template<typename> class T> struct B {
869     friend T; // expected-error {{requires a type specifier}} expected-error {{can only be classes or functions}}
870     template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
871   };
872 }
873 
874 // dr586: na
875 
876 namespace dr587 { // dr587: yes
f(bool b,const T x,T y)877   template<typename T> void f(bool b, const T x, T y) {
878     const T *p = &(b ? x : y);
879   }
880   struct S {};
881   template void f(bool, const int, int);
882   template void f(bool, const S, S);
883 }
884 
885 namespace dr588 { // dr588: yes
886   struct A { int n; }; // expected-note {{ambiguous}}
f()887   template<typename T> int f() {
888     struct S : A, T { int f() { return n; } } s;
889     int a = s.f();
890     int b = s.n; // expected-error {{found in multiple}}
891   }
892   struct B { int n; }; // expected-note {{ambiguous}}
893   int k = f<B>(); // expected-note {{here}}
894 }
895 
896 namespace dr589 { // dr589: yes
897   struct B { };
898   struct D : B { };
899   D f();
900   extern const B &b;
901   bool a;
902   const B *p = &(a ? f() : b); // expected-error {{temporary}}
903   const B *q = &(a ? D() : b); // expected-error {{temporary}}
904 }
905 
906 namespace dr590 { // dr590: yes
907   template<typename T> struct A {
908     struct B {
909       struct C {
910         A<T>::B::C f(A<T>::B::C); // ok, no 'typename' required.
911       };
912     };
913   };
f(A<T>::B::C)914   template<typename T> typename A<T>::B::C A<T>::B::C::f(A<T>::B::C) {}
915 }
916 
917 namespace dr591 { // dr591: no
918   template<typename T> struct A {
919     typedef int M;
920     struct B {
921       typedef void M;
922       struct C;
923     };
924   };
925 
926   template<typename T> struct A<T>::B::C : A<T> {
927     // FIXME: Should find member of non-dependent base class A<T>.
928     M m; // expected-error {{incomplete type 'M' (aka 'void'}}
929   };
930 }
931 
932 // dr592: na
933 // dr593 needs an IRGen test.
934 // dr594: na
935 
936 namespace dr595 { // dr595: dup 1330
937   template<class T> struct X {
fdr595::X938     void f() throw(T) {}
939   };
940   struct S {
941     X<S> xs;
942   };
943 }
944 
945 // dr597: na
946 
947 namespace dr598 { // dr598: yes
948   namespace N {
949     void f(int);
950     void f(char);
951     // Not found by ADL.
952     void g(void (*)(int));
953     void h(void (*)(int));
954 
955     namespace M {
956       struct S {};
957       int &h(void (*)(S));
958     }
959     void i(M::S);
960     void i();
961   }
962   int &g(void(*)(char));
963   int &r = g(N::f);
964   int &s = h(N::f); // expected-error {{undeclared}}
965   int &t = h(N::i);
966 }
967 
968 namespace dr599 { // dr599: partial
969   typedef int Fn();
970   struct S { operator void*(); };
971   struct T { operator Fn*(); };
972   struct U { operator int*(); operator void*(); }; // expected-note 2{{conversion}}
973   struct V { operator int*(); operator Fn*(); };
f(void * p,void (* q)(),S s,T t,U u,V v)974   void f(void *p, void (*q)(), S s, T t, U u, V v) {
975     delete p; // expected-error {{cannot delete}}
976     delete q; // expected-error {{cannot delete}}
977     delete s; // expected-error {{cannot delete}}
978     delete t; // expected-error {{cannot delete}}
979     // FIXME: This is valid, but is rejected due to a non-conforming GNU
980     // extension allowing deletion of pointers to void.
981     delete u; // expected-error {{ambiguous}}
982     delete v;
983   }
984 }
985