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