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 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6
7 // PR13819 -- __SIZE_TYPE__ is incompatible.
8 typedef __SIZE_TYPE__ size_t; // expected-error 0-1 {{extension}}
9
10 #if __cplusplus < 201103L
11 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
12 #else
13 #define fold
14 #endif
15
16 namespace dr200 { // dr200: dup 214
17 template <class T> T f(int);
18 template <class T, class U> T f(U) = delete; // expected-error 0-1{{extension}}
19
g()20 void g() {
21 f<int>(1);
22 }
23 }
24
25 // dr201 FIXME: write codegen test
26
27 namespace dr202 { // dr202: yes
28 template<typename T> T f();
29 template<int (*g)()> struct X {
30 int arr[fold(g == &f<int>) ? 1 : -1];
31 };
32 template struct X<f>;
33 }
34
35 // FIXME (export) dr204: no
36
37 namespace dr206 { // dr206: yes
38 struct S; // expected-note 2{{declaration}}
39 template<typename T> struct Q { S s; }; // expected-error {{incomplete}}
f()40 template<typename T> void f() { S s; } // expected-error {{incomplete}}
41 }
42
43 namespace dr207 { // dr207: yes
44 class A {
45 protected:
f()46 static void f() {}
47 };
48 class B : A {
49 public:
50 using A::f;
g()51 void g() {
52 A::f();
53 f();
54 }
55 };
56 }
57
58 // dr208 FIXME: write codegen test
59
60 namespace dr209 { // dr209: yes
61 class A {
62 void f(); // expected-note {{here}}
63 };
64 class B {
65 friend void A::f(); // expected-error {{private}}
66 };
67 }
68
69 // dr210 FIXME: write codegen test
70
71 namespace dr211 { // dr211: yes
72 struct A {
Adr211::A73 A() try {
74 throw 0;
75 } catch (...) {
76 return; // expected-error {{return in the catch of a function try block of a constructor}}
77 }
78 };
79 }
80
81 namespace dr213 { // dr213: yes
82 template <class T> struct A : T {
hdr213::A83 void h(T t) {
84 char &r1 = f(t);
85 int &r2 = g(t); // expected-error {{explicit qualification required to use member 'g' from dependent base class}}
86 }
87 };
88 struct B {
89 int &f(B);
90 int &g(B); // expected-note {{here}}
91 };
92 char &f(B);
93
94 template void A<B>::h(B); // expected-note {{instantiation}}
95 }
96
97 namespace dr214 { // dr214: yes
checked_cast(U from)98 template<typename T, typename U> T checked_cast(U from) { U::error; }
99 template<typename T, typename U> T checked_cast(U *from);
100 class C {};
foo(int * arg)101 void foo(int *arg) { checked_cast<const C *>(arg); }
102
103 template<typename T> T f(int);
f(U)104 template<typename T, typename U> T f(U) { T::error; }
g()105 void g() {
106 f<int>(1);
107 }
108 }
109
110 namespace dr215 { // dr215: yes
111 template<typename T> class X {
112 friend void T::foo();
113 int n;
114 };
115 struct Y {
foodr215::Y116 void foo() { (void)+X<Y>().n; }
117 };
118 }
119
120 namespace dr216 { // dr216: no
121 // FIXME: Should reject this: 'f' has linkage but its type does not,
122 // and 'f' is odr-used but not defined in this TU.
123 typedef enum { e } *E;
124 void f(E);
g(E e)125 void g(E e) { f(e); }
126
127 struct S {
128 // FIXME: Should reject this: 'f' has linkage but its type does not,
129 // and 'f' is odr-used but not defined in this TU.
130 typedef enum { e } *E;
131 void f(E);
132 };
g(S s,S::E e)133 void g(S s, S::E e) { s.f(e); }
134 }
135
136 namespace dr217 { // dr217: yes
137 template<typename T> struct S {
138 void f(int);
139 };
f(int=0)140 template<typename T> void S<T>::f(int = 0) {} // expected-error {{default arguments cannot be added}}
141 }
142
143 namespace dr218 { // dr218: yes
144 namespace A {
145 struct S {};
146 void f(S);
147 }
148 namespace B {
149 struct S {};
150 void f(S);
151 }
152
153 struct C {
154 int f;
test1dr218::C155 void test1(A::S as) { f(as); } // expected-error {{called object type 'int'}}
test2dr218::C156 void test2(A::S as) { void f(); f(as); } // expected-error {{too many arguments}} expected-note {{}}
test3dr218::C157 void test3(A::S as) { using A::f; f(as); } // ok
test4dr218::C158 void test4(A::S as) { using B::f; f(as); } // ok
test5dr218::C159 void test5(A::S as) { int f; f(as); } // expected-error {{called object type 'int'}}
test6dr218::C160 void test6(A::S as) { struct f {}; (void) f(as); } // expected-error {{no matching conversion}} expected-note +{{}}
161 };
162
163 namespace D {
164 struct S {};
165 struct X { void operator()(S); } f;
166 }
testD(D::S ds)167 void testD(D::S ds) { f(ds); } // expected-error {{undeclared identifier}}
168
169 namespace E {
170 struct S {};
171 struct f { f(S); };
172 }
testE(E::S es)173 void testE(E::S es) { f(es); } // expected-error {{undeclared identifier}}
174
175 namespace F {
176 struct S {
f(S,T)177 template<typename T> friend void f(S, T) {}
178 };
179 }
testF(F::S fs)180 void testF(F::S fs) { f(fs, 0); }
181
182 namespace G {
183 namespace X {
184 int f;
185 struct A {};
186 }
187 namespace Y {
188 template<typename T> void f(T);
189 struct B {};
190 }
191 template<typename A, typename B> struct C {};
192 }
testG(G::C<G::X::A,G::Y::B> gc)193 void testG(G::C<G::X::A, G::Y::B> gc) { f(gc); }
194 }
195
196 // dr219: na
197 // dr220: na
198
199 namespace dr221 { // dr221: yes
200 struct A { // expected-note 2-4{{candidate}}
201 A &operator=(int&); // expected-note 2{{candidate}}
202 A &operator+=(int&);
203 static A &operator=(A&, double&); // expected-error {{cannot be a static member}}
204 static A &operator+=(A&, double&); // expected-error {{cannot be a static member}}
205 friend A &operator=(A&, char&); // expected-error {{must be a non-static member function}}
206 friend A &operator+=(A&, char&);
207 };
208 A &operator=(A&, float&); // expected-error {{must be a non-static member function}}
209 A &operator+=(A&, float&);
210
test(A a,int n,char c,float f)211 void test(A a, int n, char c, float f) {
212 a = n;
213 a += n;
214 a = c; // expected-error {{no viable}}
215 a += c;
216 a = f; // expected-error {{no viable}}
217 a += f;
218 }
219 }
220
221 namespace dr222 { // dr222: dup 637
f(int a,int b,int c,int * x)222 void f(int a, int b, int c, int *x) {
223 #pragma clang diagnostic push
224 #pragma clang diagnostic warning "-Wunsequenced"
225 void((a += b) += c);
226 void((a += b) + (a += c)); // expected-warning {{multiple unsequenced modifications to 'a'}}
227
228 x[a++] = a;
229 #if __cplusplus < 201703L
230 // expected-warning@-2 {{unsequenced modification and access to 'a'}}
231 #endif
232
233 a = b = 0; // ok, read and write of 'b' are sequenced
234
235 a = (b = a++);
236 #if __cplusplus < 201703L
237 // expected-warning@-2 {{multiple unsequenced modifications to 'a'}}
238 #endif
239 a = (b = ++a);
240 #pragma clang diagnostic pop
241 }
242 }
243
244 // dr223: na
245
246 namespace dr224 { // dr224: no
247 namespace example1 {
248 template <class T> class A {
249 typedef int type;
250 A::type a;
251 A<T>::type b;
252 A<T*>::type c; // expected-error {{missing 'typename'}}
253 ::dr224::example1::A<T>::type d;
254
255 class B {
256 typedef int type;
257
258 A::type a;
259 A<T>::type b;
260 A<T*>::type c; // expected-error {{missing 'typename'}}
261 ::dr224::example1::A<T>::type d;
262
263 B::type e;
264 A<T>::B::type f;
265 A<T*>::B::type g; // expected-error {{missing 'typename'}}
266 typename A<T*>::B::type h;
267 };
268 };
269
270 template <class T> class A<T*> {
271 typedef int type;
272 A<T*>::type a;
273 A<T>::type b; // expected-error {{missing 'typename'}}
274 };
275
276 template <class T1, class T2, int I> struct B {
277 typedef int type;
278 B<T1, T2, I>::type b1;
279 B<T2, T1, I>::type b2; // expected-error {{missing 'typename'}}
280
281 typedef T1 my_T1;
282 static const int my_I = I;
283 static const int my_I2 = I+0;
284 static const int my_I3 = my_I;
285 B<my_T1, T2, my_I>::type b3; // FIXME: expected-error {{missing 'typename'}}
286 B<my_T1, T2, my_I2>::type b4; // expected-error {{missing 'typename'}}
287 B<my_T1, T2, my_I3>::type b5; // FIXME: expected-error {{missing 'typename'}}
288 };
289 }
290
291 namespace example2 {
292 template <int, typename T> struct X { typedef T type; };
293 template <class T> class A {
294 static const int i = 5;
295 X<i, int>::type w;
296 X<A::i, char>::type x;
297 X<A<T>::i, double>::type y;
298 X<A<T*>::i, long>::type z; // expected-error {{missing 'typename'}}
299 int f();
300 };
f()301 template <class T> int A<T>::f() {
302 return i;
303 }
304 }
305 }
306
307 // dr225: yes
dr225_f(T t)308 template<typename T> void dr225_f(T t) { dr225_g(t); } // expected-error {{call to function 'dr225_g' that is neither visible in the template definition nor found by argument-dependent lookup}}
309 void dr225_g(int); // expected-note {{should be declared prior to the call site}}
310 template void dr225_f(int); // expected-note {{in instantiation of}}
311
312 namespace dr226 { // dr226: no
f()313 template<typename T = void> void f() {}
314 #if __cplusplus < 201103L
315 // expected-error@-2 {{extension}}
316 // FIXME: This appears to be wrong: default arguments for function templates
317 // are listed as a defect (in c++98) not an extension. EDG accepts them in
318 // strict c++98 mode.
319 #endif
320 template<typename T> struct S {
321 template<typename U = void> void g();
322 #if __cplusplus < 201103L
323 // expected-error@-2 {{extension}}
324 #endif
325 template<typename U> struct X;
326 template<typename U> void h();
327 };
g()328 template<typename T> template<typename U> void S<T>::g() {}
329 template<typename T> template<typename U = void> struct S<T>::X {}; // expected-error {{cannot add a default template arg}}
h()330 template<typename T> template<typename U = void> void S<T>::h() {} // expected-error {{cannot add a default template arg}}
331
332 template<typename> void friend_h();
333 struct A {
334 // FIXME: This is ill-formed.
335 template<typename=void> struct friend_B;
336 // FIXME: f, h, and i are ill-formed.
337 // f is ill-formed because it is not a definition.
338 // h and i are ill-formed because they are not the only declarations of the
339 // function in the translation unit.
340 template<typename=void> void friend_f();
friend_gdr226::A341 template<typename=void> void friend_g() {}
friend_hdr226::A342 template<typename=void> void friend_h() {}
friend_idr226::A343 template<typename=void> void friend_i() {}
344 #if __cplusplus < 201103L
345 // expected-error@-5 {{extension}} expected-error@-4 {{extension}}
346 // expected-error@-4 {{extension}} expected-error@-3 {{extension}}
347 #endif
348 };
349 template<typename> void friend_i();
350
foo(X)351 template<typename=void, typename X> void foo(X) {}
352 template<typename=void, typename X> struct Foo {}; // expected-error {{missing a default argument}} expected-note {{here}}
353 #if __cplusplus < 201103L
354 // expected-error@-3 {{extension}}
355 #endif
356
357 template<typename=void, typename X, typename, typename Y> int foo(X, Y);
358 template<typename, typename X, typename=void, typename Y> int foo(X, Y);
359 int x = foo(0, 0);
360 #if __cplusplus < 201103L
361 // expected-error@-4 {{extension}}
362 // expected-error@-4 {{extension}}
363 #endif
364 }
365
dr227(bool b)366 void dr227(bool b) { // dr227: yes
367 if (b)
368 int n;
369 else
370 int n;
371 }
372
373 namespace dr228 { // dr228: yes
374 template <class T> struct X {
375 void f();
376 };
377 template <class T> struct Y {
gdr228::Y378 void g(X<T> x) { x.template X<T>::f(); }
379 };
380 }
381
382 namespace dr229 { // dr229: yes
383 template<typename T> void f();
f()384 template<typename T> void f<T*>() {} // expected-error {{function template partial specialization}}
f()385 template<> void f<int>() {}
386 }
387
388 namespace dr230 { // dr230: yes
389 struct S {
Sdr230::S390 S() { f(); } // expected-warning {{call to pure virtual member function}}
391 virtual void f() = 0; // expected-note {{declared here}}
392 };
393 }
394
395 namespace dr231 { // dr231: yes
396 namespace outer {
397 namespace inner {
398 int i; // expected-note {{here}}
399 }
f()400 void f() { using namespace inner; }
401 int j = i; // expected-error {{undeclared identifier 'i'; did you mean 'inner::i'?}}
402 }
403 }
404
405 // dr234: na
406 // dr235: na
407
408 namespace dr236 { // dr236: yes
409 void *p = int();
410 #if __cplusplus < 201103L
411 // expected-warning@-2 {{null pointer}}
412 #else
413 // expected-error@-4 {{cannot initialize}}
414 #endif
415 }
416
417 namespace dr237 { // dr237: dup 470
fdr237::A418 template<typename T> struct A { void f() { T::error; } };
419 template<typename T> struct B : A<T> {};
420 template struct B<int>; // ok
421 }
422
423 namespace dr239 { // dr239: yes
424 namespace NS {
425 class T {};
426 void f(T);
427 float &g(T, int);
428 }
429 NS::T parm;
430 int &g(NS::T, float);
main()431 int main() {
432 f(parm);
433 float &r = g(parm, 1);
434 extern int &g(NS::T, float);
435 int &s = g(parm, 1);
436 }
437 }
438
439 // dr240: dup 616
440
441 namespace dr241 { // dr241: yes
442 namespace A {
443 struct B {};
444 template <int X> void f(); // expected-note 3{{candidate}}
445 template <int X> void g(B);
446 }
447 namespace C {
448 template <class T> void f(T t); // expected-note 2{{candidate}}
449 template <class T> void g(T t); // expected-note {{candidate}}
450 }
h(A::B b)451 void h(A::B b) {
452 f<3>(b); // expected-error 0-1{{C++20 extension}} expected-error {{no matching}}
453 g<3>(b); // expected-error 0-1{{C++20 extension}}
454 A::f<3>(b); // expected-error {{no matching}}
455 A::g<3>(b);
456 C::f<3>(b); // expected-error {{no matching}}
457 C::g<3>(b); // expected-error {{no matching}}
458 using C::f;
459 using C::g;
460 f<3>(b); // expected-error {{no matching}}
461 g<3>(b);
462 }
463 }
464
465 namespace dr243 { // dr243: yes
466 struct B;
467 struct A {
468 A(B); // expected-note {{candidate}}
469 };
470 struct B {
471 operator A() = delete; // expected-error 0-1{{extension}} expected-note {{candidate}}
472 } b;
473 A a1(b);
474 A a2 = b; // expected-error {{ambiguous}}
475 }
476
477 namespace dr244 { // dr244: 11
478 struct B {}; // expected-note {{type 'dr244::B' found by destructor name lookup}}
479 struct D : B {};
480
481 D D_object;
482 typedef B B_alias;
483 B* B_ptr = &D_object;
484
f()485 void f() {
486 D_object.~B(); // expected-error {{does not match the type 'dr244::D' of the object being destroyed}}
487 D_object.B::~B();
488 D_object.D::~B(); // FIXME: Missing diagnostic for this.
489 B_ptr->~B();
490 B_ptr->~B_alias();
491 B_ptr->B_alias::~B();
492 B_ptr->B_alias::~B_alias();
493 B_ptr->dr244::~B(); // expected-error {{refers to a member in namespace}}
494 B_ptr->dr244::~B_alias(); // expected-error {{refers to a member in namespace}}
495 }
496
497 template<typename T, typename U>
f(T * B_ptr,U D_object)498 void f(T *B_ptr, U D_object) {
499 D_object.~B(); // FIXME: Missing diagnostic for this.
500 D_object.B::~B();
501 D_object.D::~B(); // FIXME: Missing diagnostic for this.
502 B_ptr->~B();
503 B_ptr->~B_alias();
504 B_ptr->B_alias::~B();
505 B_ptr->B_alias::~B_alias();
506 B_ptr->dr244::~B(); // expected-error {{does not refer to a type name}}
507 B_ptr->dr244::~B_alias(); // expected-error {{does not refer to a type name}}
508 }
509 template void f<B, D>(B*, D);
510
511 namespace N {
512 template<typename T> struct E {};
513 typedef E<int> F;
514 }
g(N::F f)515 void g(N::F f) {
516 typedef N::F G; // expected-note {{found by destructor name lookup}}
517 f.~G();
518 f.G::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
519 f.G::~F(); // expected-error {{undeclared identifier 'F' in destructor name}}
520 f.G::~G();
521 // This is technically ill-formed; E is looked up in 'N::' and names the
522 // class template, not the injected-class-name of the class. But that's
523 // probably a bug in the standard.
524 f.N::F::~E(); // expected-error {{ISO C++ requires the name after '::~' to be found in the same scope as the name before '::~'}}
525 // This is valid; we look up the second F in the same scope in which we
526 // found the first one, that is, 'N::'.
527 f.N::F::~F();
528 // This is technically ill-formed; G is looked up in 'N::' and is not found.
529 // Rejecting this seems correct, but most compilers accept, so we do also.
530 f.N::F::~G(); // expected-error {{qualified destructor name only found in lexical scope; omit the qualifier to find this type name by unqualified lookup}}
531 }
532
533 // Bizarrely, compilers perform lookup in the scope for qualified destructor
534 // names, if the nested-name-specifier is non-dependent. Ensure we diagnose
535 // this.
536 namespace QualifiedLookupInScope {
537 namespace N {
538 template <typename> struct S { struct Inner {}; };
539 }
f(typename N::S<U>::Inner * p)540 template <typename U> void f(typename N::S<U>::Inner *p) {
541 typedef typename N::S<U>::Inner T;
542 p->::dr244::QualifiedLookupInScope::N::S<U>::Inner::~T(); // expected-error {{no type named 'T' in}}
543 }
544 template void f<int>(N::S<int>::Inner *); // expected-note {{instantiation of}}
545
g(U * p)546 template <typename U> void g(U *p) {
547 typedef U T;
548 p->T::~T();
549 p->U::~T();
550 p->::dr244::QualifiedLookupInScope::N::S<int>::Inner::~T(); // expected-error {{'T' does not refer to a type name}}
551 }
552 template void g(N::S<int>::Inner *);
553 }
554 }
555
556 namespace dr245 { // dr245: yes
557 struct S {
558 enum E {}; // expected-note {{here}}
559 class E *p; // expected-error {{does not match previous declaration}}
560 };
561 }
562
563 namespace dr246 { // dr246: yes
564 struct S {
Sdr246::S565 S() try { // expected-note {{try block}}
566 throw 0;
567 X: ;
568 } catch (int) {
569 goto X; // expected-error {{cannot jump}}
570 }
571 };
572 }
573
574 namespace dr247 { // dr247: yes
575 struct A {};
576 struct B : A {
577 void f();
578 void f(int);
579 };
580 void (A::*f)() = (void (A::*)())&B::f;
581
582 struct C {
583 void f();
584 void f(int);
585 };
586 struct D : C {};
587 void (C::*g)() = &D::f;
588 void (D::*h)() = &D::f;
589
590 struct E {
591 void f();
592 };
593 struct F : E {
594 using E::f;
595 void f(int);
596 };
597 void (F::*i)() = &F::f;
598 }
599
600 namespace dr248 { // dr248: sup P1949
601 int \u040d\u040e = 0;
602 }
603
604 namespace dr249 { // dr249: yes
605 template<typename T> struct X { void f(); };
f()606 template<typename T> void X<T>::f() {}
607 }
608
609 namespace dr250 { // dr250: yes
610 typedef void (*FPtr)(double x[]);
611
612 template<int I> void f(double x[]);
613 FPtr fp = &f<3>;
614
615 template<int I = 3> void g(double x[]); // expected-error 0-1{{extension}}
616 FPtr gp = &g<>;
617 }
618
619 namespace dr252 { // dr252: yes
620 struct A {
621 void operator delete(void*); // expected-note {{found}}
622 };
623 struct B {
624 void operator delete(void*); // expected-note {{found}}
625 };
626 struct C : A, B {
627 virtual ~C();
628 };
~C()629 C::~C() {} // expected-error {{'operator delete' found in multiple base classes}}
630
631 struct D {
632 void operator delete(void*, int); // expected-note {{here}}
633 virtual ~D();
634 };
~D()635 D::~D() {} // expected-error {{no suitable member 'operator delete'}}
636
637 struct E {
638 void operator delete(void*, int);
639 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note 1-2 {{here}}
640 virtual ~E(); // expected-error 0-1 {{attempt to use a deleted function}}
641 };
~E()642 E::~E() {} // expected-error {{attempt to use a deleted function}}
643
644 struct F {
645 // If both functions are available, the first one is a placement delete.
646 void operator delete(void*, size_t);
647 void operator delete(void*) = delete; // expected-error 0-1{{extension}} expected-note {{here}}
648 virtual ~F();
649 };
~F()650 F::~F() {} // expected-error {{attempt to use a deleted function}}
651
652 struct G {
653 void operator delete(void*, size_t);
654 virtual ~G();
655 };
~G()656 G::~G() {}
657 }
658
659 namespace dr254 { // dr254: yes
660 template<typename T> struct A {
661 typedef typename T::type type; // ok even if this is a typedef-name, because
662 // it's not an elaborated-type-specifier
663 typedef struct T::type foo; // expected-error {{typedef 'type' cannot be referenced with a struct specifier}}
664 };
665 struct B { struct type {}; };
666 struct C { typedef struct {} type; }; // expected-note {{here}}
667 A<B>::type n;
668 A<C>::type n; // expected-note {{instantiation of}}
669 }
670
671 // dr256: dup 624
672
673 namespace dr257 { // dr257: yes
674 struct A { A(int); }; // expected-note {{here}}
675 struct B : virtual A {
Bdr257::B676 B() {}
677 virtual void f() = 0;
678 };
679 struct C : B {
Cdr257::C680 C() {}
681 };
682 struct D : B {
Ddr257::D683 D() {} // expected-error {{must explicitly initialize the base class 'dr257::A'}}
684 void f();
685 };
686 }
687
688 namespace dr258 { // dr258: yes
689 struct A {
690 void f(const int);
691 template<typename> void g(int);
692 float &h() const;
693 };
694 struct B : A {
695 using A::f;
696 using A::g;
697 using A::h;
698 int &f(int);
699 template<int> int &g(int); // expected-note {{candidate}}
700 int &h();
701 } b;
702 int &w = b.f(0);
703 int &x = b.g<int>(0); // expected-error {{no match}}
704 int &y = b.h();
705 float &z = const_cast<const B&>(b).h();
706
707 struct C {
708 virtual void f(const int) = 0;
709 };
710 struct D : C {
711 void f(int);
712 } d;
713
714 struct E {
715 virtual void f() = 0; // expected-note {{unimplemented}}
716 };
717 struct F : E {
fdr258::F718 void f() const {}
719 } f; // expected-error {{abstract}}
720 }
721
722 namespace dr259 { // dr259: 4
723 template<typename T> struct A {};
724 template struct A<int>; // expected-note {{previous}}
725 template struct A<int>; // expected-error {{duplicate explicit instantiation}}
726
727 template<> struct A<float>; // expected-note {{previous}}
728 template struct A<float>; // expected-warning {{has no effect}}
729
730 template struct A<char>; // expected-note {{here}}
731 template<> struct A<char>; // expected-error {{explicit specialization of 'dr259::A<char>' after instantiation}}
732
733 template<> struct A<double>;
734 template<> struct A<double>;
735 template<> struct A<double> {}; // expected-note {{here}}
736 template<> struct A<double> {}; // expected-error {{redefinition}}
737
738 template<typename T> struct B; // expected-note {{here}}
739 template struct B<int>; // expected-error {{undefined}}
740
741 template<> struct B<float>; // expected-note {{previous}}
742 template struct B<float>; // expected-warning {{has no effect}}
743 }
744
745 // FIXME: When dr260 is resolved, also add tests for DR507.
746
747 namespace dr261 { // dr261: no
748 #pragma clang diagnostic push
749 #pragma clang diagnostic warning "-Wused-but-marked-unused"
750
751 // FIXME: This is ill-formed, with a diagnostic required, because operator new
752 // and operator delete are inline and odr-used, but not defined in this
753 // translation unit.
754 // We're also missing the -Wused-but-marked-unused diagnostic here.
755 struct A {
756 inline void *operator new(size_t) __attribute__((unused));
757 inline void operator delete(void*) __attribute__((unused));
Adr261::A758 A() {}
759 };
760
761 // FIXME: This is ill-formed, with a required diagnostic, for the same
762 // reason.
763 struct B {
764 inline void operator delete(void*) __attribute__((unused));
~Bdr261::B765 ~B() {}
766 };
767 struct C {
768 inline void operator delete(void*) __attribute__((unused));
~Cdr261::C769 virtual ~C() {} // expected-warning {{'operator delete' was marked unused but was used}}
770 };
771
772 struct D {
773 inline void operator delete(void*) __attribute__((unused));
774 };
h()775 void h() { C::operator delete(0); } // expected-warning {{marked unused but was used}}
776
777 #pragma clang diagnostic pop
778 }
779
780 namespace dr262 { // dr262: yes
781 int f(int = 0, ...);
782 int k = f();
783 int l = f(0);
784 int m = f(0, 0);
785 }
786
787 namespace dr263 { // dr263: yes
788 struct X {};
789 struct Y {
790 #if __cplusplus < 201103L
791 friend X::X() throw();
792 friend X::~X() throw();
793 #elif __cplusplus <= 201703L
794 friend constexpr X::X() noexcept;
795 friend X::~X();
796 #else
797 friend constexpr X::X() noexcept;
798 friend constexpr X::~X();
799 #endif
800 Y::Y(); // expected-error {{extra qualification}}
801 Y::~Y(); // expected-error {{extra qualification}}
802 };
803 }
804
805 // dr265: dup 353
806 // dr266: na
807 // dr269: na
808 // dr270: na
809
810 namespace dr272 { // dr272: yes
811 struct X {
fdr272::X812 void f() {
813 this->~X();
814 X::~X();
815 ~X(); // expected-error {{unary expression}}
816 }
817 };
818 }
819
820 #include <stdarg.h>
821 #include <stddef.h>
822 namespace dr273 { // dr273: yes
823 struct A {
824 int n;
825 };
826 void operator&(A);
f(A a,...)827 void f(A a, ...) {
828 offsetof(A, n);
829 va_list val;
830 va_start(val, a);
831 va_end(val);
832 }
833 }
834
835 // dr274: na
836
837 namespace dr275 { // dr275: no
838 namespace N {
f(T)839 template <class T> void f(T) {} // expected-note 1-4{{here}}
g(T)840 template <class T> void g(T) {} // expected-note {{candidate}}
841 template <> void f(int);
842 template <> void f(char);
843 template <> void f(double);
844 template <> void g(char);
845 }
846
847 using namespace N;
848
849 namespace M {
f(char)850 template <> void N::f(char) {} // expected-error {{'M' does not enclose namespace 'N'}}
g(T)851 template <class T> void g(T) {}
g(char)852 template <> void g(char) {}
853 template void f(long);
854 #if __cplusplus >= 201103L
855 // FIXME: this should be rejected in c++98 too
856 // expected-error@-3 {{must occur in namespace 'N'}}
857 #endif
858 template void N::f(unsigned long);
859 #if __cplusplus >= 201103L
860 // FIXME: this should be rejected in c++98 too
861 // expected-error@-3 {{not in a namespace enclosing 'N'}}
862 #endif
863 template void h(long); // expected-error {{does not refer to a function template}}
f(double)864 template <> void f(double) {} // expected-error {{no function template matches}}
865 }
866
g(T)867 template <class T> void g(T) {} // expected-note {{candidate}}
868
f(char)869 template <> void N::f(char) {}
f(int)870 template <> void f(int) {} // expected-error {{no function template matches}}
871
872 template void f(short);
873 #if __cplusplus >= 201103L
874 // FIXME: this should be rejected in c++98 too
875 // expected-error@-3 {{must occur in namespace 'N'}}
876 #endif
877 template void N::f(unsigned short);
878
879 // FIXME: this should probably be valid. the wording from the issue
880 // doesn't clarify this, but it follows from the usual rules.
881 template void g(int); // expected-error {{ambiguous}}
882
883 // FIXME: likewise, this should also be valid.
f(T)884 template<typename T> void f(T) {} // expected-note {{candidate}}
885 template void f(short); // expected-error {{ambiguous}}
886 }
887
888 // dr276: na
889
890 namespace dr277 { // dr277: yes
891 typedef int *intp;
892 int *p = intp();
893 int a[fold(intp() ? -1 : 1)];
894 }
895
896 namespace dr280 { // dr280: yes
897 typedef void f0();
898 typedef void f1(int);
899 typedef void f2(int, int);
900 typedef void f3(int, int, int);
901 struct A {
902 operator f1*(); // expected-note {{here}} expected-note {{candidate}}
903 operator f2*();
904 };
905 struct B {
906 operator f0*(); // expected-note {{candidate}}
907 private:
908 operator f3*(); // expected-note {{here}} expected-note {{candidate}}
909 };
910 struct C {
911 operator f0*(); // expected-note {{candidate}}
912 operator f1*(); // expected-note {{candidate}}
913 operator f2*(); // expected-note {{candidate}}
914 operator f3*(); // expected-note {{candidate}}
915 };
916 struct D : private A, B { // expected-note {{here}}
917 operator f2*(); // expected-note {{candidate}}
918 } d;
919 struct E : C, D {} e;
g()920 void g() {
921 d(); // ok, public
922 d(0); // expected-error {{private member of 'dr280::A'}}
923 d(0, 0); // ok, suppressed by member in D
924 d(0, 0, 0); // expected-error {{private member of 'dr280::B'}}
925 e(); // expected-error {{ambiguous}}
926 e(0); // expected-error {{ambiguous}}
927 e(0, 0); // expected-error {{ambiguous}}
928 e(0, 0, 0); // expected-error {{ambiguous}}
929 }
930 }
931
932 namespace dr281 { // dr281: no
933 void a();
934 inline void b();
935
936 void d();
937 inline void e();
938
939 struct S {
940 friend inline void a(); // FIXME: ill-formed
941 friend inline void b();
942 friend inline void c(); // FIXME: ill-formed
d()943 friend inline void d() {}
e()944 friend inline void e() {}
f()945 friend inline void f() {}
946 };
947 }
948
949 namespace dr283 { // dr283: yes
950 template<typename T> // expected-note 2{{here}}
951 struct S {
952 friend class T; // expected-error {{shadows}}
953 class T; // expected-error {{shadows}}
954 };
955 }
956
957 namespace dr284 { // dr284: no
958 namespace A {
959 struct X;
960 enum Y {};
961 class Z {};
962 }
963 namespace B {
964 struct W;
965 using A::X;
966 using A::Y;
967 using A::Z;
968 }
969 struct B::V {}; // expected-error {{no struct named 'V'}}
970 struct B::W {};
971 struct B::X {}; // FIXME: ill-formed
972 enum B::Y e; // ok per dr417
973 class B::Z z; // ok per dr417
974
975 struct C {
976 struct X;
977 enum Y {};
978 class Z {};
979 };
980 struct D : C {
981 struct W;
982 using C::X;
983 using C::Y;
984 using C::Z;
985 };
986 struct D::V {}; // expected-error {{no struct named 'V'}}
987 struct D::W {};
988 struct D::X {}; // FIXME: ill-formed
989 enum D::Y e2; // ok per dr417
990 class D::Z z2; // ok per dr417
991 }
992
993 namespace dr285 { // dr285: yes
994 template<typename T> void f(T, int); // expected-note {{match}}
995 template<typename T> void f(int, T); // expected-note {{match}}
f(int,int)996 template<> void f<int>(int, int) {} // expected-error {{ambiguous}}
997 }
998
999 namespace dr286 { // dr286: yes
1000 template<class T> struct A {
1001 class C {
1002 template<class T2> struct B {}; // expected-note {{here}}
1003 };
1004 };
1005
1006 template<class T>
1007 template<class T2>
1008 struct A<T>::C::B<T2*> { };
1009
1010 A<short>::C::B<int*> absip; // expected-error {{private}}
1011 }
1012
1013 // dr288: na
1014
1015 namespace dr289 { // dr289: yes
1016 struct A; // expected-note {{forward}}
1017 struct B : A {}; // expected-error {{incomplete}}
1018
1019 template<typename T> struct C { typename T::error error; }; // expected-error {{cannot be used prior to '::'}}
1020 struct D : C<int> {}; // expected-note {{instantiation}}
1021 }
1022
1023 // dr290: na
1024 // dr291: dup 391
1025 // dr292 FIXME: write a codegen test
1026
1027 namespace dr294 { // dr294: no
1028 void f() throw(int);
1029 #if __cplusplus > 201402L
1030 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1031 #endif
main()1032 int main() {
1033 (void)static_cast<void (*)() throw()>(f); // FIXME: ill-formed in C++14 and before
1034 #if __cplusplus > 201402L
1035 // FIXME: expected-error@-2 {{not allowed}}
1036 //
1037 // Irony: the above is valid in C++17 and beyond, but that's exactly when
1038 // we reject it. In C++14 and before, this is ill-formed because an
1039 // exception-specification is not permitted in a type-id. In C++17, this is
1040 // valid because it's the inverse of a standard conversion sequence
1041 // containing a function pointer conversion. (Well, it's actually not valid
1042 // yet, as a static_cast is not permitted to reverse a function pointer
1043 // conversion, but that is being changed by core issue).
1044 #endif
1045 (void)static_cast<void (*)() throw(int)>(f); // FIXME: ill-formed in C++14 and before
1046 #if __cplusplus > 201402L
1047 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1048 #endif
1049
1050 void (*p)() throw() = f; // expected-error-re {{{{not superset|different exception specification}}}}
1051 void (*q)() throw(int) = f;
1052 #if __cplusplus > 201402L
1053 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1054 #endif
1055 }
1056 }
1057
1058 namespace dr295 { // dr295: 3.7
1059 typedef int f();
1060 const f g; // expected-warning {{'const' qualifier on function type 'dr295::f' (aka 'int ()') has no effect}}
1061 f &r = g;
1062 template<typename T> struct X {
1063 const T &f;
1064 };
1065 X<f> x = {g};
1066
1067 typedef int U();
1068 typedef const U U; // expected-warning {{'const' qualifier on function type 'dr295::U' (aka 'int ()') has no effect}}
1069
1070 typedef int (*V)();
1071 typedef volatile U *V; // expected-warning {{'volatile' qualifier on function type 'dr295::U' (aka 'int ()') has no effect}}
1072 }
1073
1074 namespace dr296 { // dr296: yes
1075 struct A {
operator intdr296::A1076 static operator int() { return 0; } // expected-error {{static}}
1077 };
1078 }
1079
1080 namespace dr298 { // dr298: yes
1081 struct A {
1082 typedef int type;
1083 A();
1084 ~A();
1085 };
1086 typedef A B; // expected-note {{here}}
1087 typedef const A C; // expected-note {{here}}
1088
1089 A::type i1;
1090 B::type i2;
1091 C::type i3;
1092
1093 struct A a;
1094 struct B b; // expected-error {{typedef 'B' cannot be referenced with a struct specifier}}
1095 struct C c; // expected-error {{typedef 'C' cannot be referenced with a struct specifier}}
1096
B()1097 B::B() {} // expected-error {{a type specifier is required}}
A()1098 B::A() {} // ok
~C()1099 C::~C() {} // expected-error {{destructor cannot be declared using a typedef 'dr298::C' (aka 'const dr298::A') of the class name}}
1100
1101 typedef struct D E; // expected-note {{here}}
1102 struct E {}; // expected-error {{conflicts with typedef}}
1103
1104 struct F {
1105 ~F();
1106 };
1107 typedef const F G;
~F()1108 G::~F() {} // ok
1109 }
1110
1111 namespace dr299 { // dr299: yes c++11
1112 struct S {
1113 operator int();
1114 };
1115 struct T {
1116 operator int(); // expected-note {{}}
1117 operator unsigned short(); // expected-note {{}}
1118 };
1119 // FIXME: should this apply to c++98 mode?
1120 int *p = new int[S()]; // expected-error 0-1{{extension}}
1121 int *q = new int[T()]; // expected-error {{ambiguous}}
1122 }
1123