Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr1xx.cpp
blob60e80a4c0e1c4f98cde1d2a7fc932d682b9056e5
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8 namespace dr100 { // dr100: yes
9 template<const char (*)[4]> struct A {}; // expected-note 0-1{{declared here}}
10 template<const char (&)[4]> struct B {}; // expected-note 0-1{{declared here}}
11 template<const char *> struct C {}; // expected-note 0-1{{declared here}}
12 template<const char &> struct D {}; // expected-note 0-1{{declared here}}
13 A<&"foo"> a; // #100a
14 B<"bar"> b; // #100b
15 C<"baz"> c; // #100c
16 D<*"quux"> d; // #100d
17 #if __cplusplus < 201703L
18 // expected-error@#100a {{does not refer to any declaration}}
19 // expected-error@#100b {{does not refer to any declaration}}
20 // expected-error@#100c {{does not refer to any declaration}}
21 // expected-error@#100d {{does not refer to any declaration}}
22 #else
23 // expected-error@#100a {{pointer to string literal is not allowed in a template argument}}
24 // expected-error@#100b {{reference to string literal is not allowed in a template argument}}
25 // expected-error@#100c {{pointer to subobject of string literal is not allowed in a template argument}}
26 // expected-error@#100d {{reference to subobject of string literal is not allowed in a template argument}}
27 #endif
30 namespace dr101 { // dr101: 3.5
31 extern "C" void dr101_f();
32 typedef unsigned size_t;
33 namespace X {
34 extern "C" void dr101_f();
35 typedef unsigned size_t;
37 using X::dr101_f;
38 using X::size_t;
39 extern "C" void dr101_f();
40 typedef unsigned size_t;
43 namespace dr102 { // dr102: yes
44 namespace A {
45 template<typename T> T f(T a, T b) { return a + b; } // expected-error {{neither visible in the template definition nor found by argument-dependent lookup}}
47 namespace B {
48 struct S {};
50 B::S operator+(B::S, B::S); // expected-note {{should be declared prior to the call site or in namespace 'dr102::B'}}
51 template B::S A::f(B::S, B::S); // expected-note {{in instantiation of}}
54 // dr103: na
55 // dr104: na lib
56 // dr105: na
58 namespace dr106 { // dr106: sup 540
59 typedef int &r1;
60 typedef r1 &r1;
61 typedef const r1 r1; // expected-warning {{has no effect}}
62 typedef const r1 &r1; // expected-warning {{has no effect}}
64 typedef const int &r2;
65 typedef r2 &r2;
66 typedef const r2 r2; // expected-warning {{has no effect}}
67 typedef const r2 &r2; // expected-warning {{has no effect}}
70 namespace dr107 { // dr107: yes
71 struct S {};
72 extern "C" S operator+(S, S) { return S(); }
75 namespace dr108 { // dr108: yes
76 template<typename T> struct A {
77 struct B { typedef int X; };
78 B::X x;
79 #if __cplusplus <= 201703L
80 // expected-error@-2 {{implicit 'typename' is a C++20 extension}}
81 #endif
82 struct C : B { X x; }; // expected-error {{unknown type name}}
84 template<> struct A<int>::B { int X; };
87 namespace dr109 { // dr109: yes
88 struct A { template<typename T> void f(T); };
89 template<typename T> struct B : T {
90 using T::template f; // expected-error {{'template' keyword not permitted here}}
91 using T::template f<int>; // expected-error {{'template' keyword not permitted here}} expected-error {{using declaration cannot refer to a template specialization}}
92 // FIXME: We shouldn't suggest using the 'template' keyword in a location where it's not valid.
93 using T::f<int>; // expected-error {{use 'template' keyword}} expected-error {{using declaration cannot refer to a template specialization}}
94 void g() { this->f<int>(123); } // expected-error {{use 'template' keyword}}
98 namespace dr111 { // dr111: dup 535
99 struct A { A(); A(volatile A&, int = 0); A(A&, const char * = "foo"); };
100 struct B : A { B(); }; // expected-note +{{would lose const qualifier}} expected-note {{requires 0 arguments}}
101 const B b1;
102 B b2(b1); // expected-error {{no matching constructor}}
105 namespace dr112 { // dr112: yes
106 struct T { int n; };
107 typedef T Arr[1];
109 const T a1[1] = {};
110 volatile T a2[1] = {};
111 const Arr a3 = {};
112 volatile Arr a4 = {};
113 template<const volatile T*> struct X {};
114 X<a1> x1;
115 X<a2> x2;
116 X<a3> x3;
117 X<a4> x4;
118 #if __cplusplus < 201103L
119 // expected-error@-5 {{internal linkage}} expected-note@-10 {{here}}
120 // expected-error@-4 {{internal linkage}} expected-note@-9 {{here}}
121 #else
122 // FIXME: Test this somehow.
123 #endif
126 namespace dr113 { // dr113: yes
127 extern void (*p)();
128 void f() {
129 no_such_function(); // expected-error {{undeclared}}
130 p();
132 void g();
133 void (*p)() = &g;
136 namespace dr114 { // dr114: yes
137 struct A {
138 virtual void f(int) = 0; // expected-note {{unimplemented}}
140 struct B : A {
141 template<typename T> void f(T);
142 void g() { f(0); }
143 } b; // expected-error {{abstract}}
146 namespace dr115 { // dr115: yes
147 template<typename T> int f(T); // expected-note +{{}}
148 template<typename T> int g(T); // expected-note +{{}}
149 template<typename T> int g(T, int); // expected-note +{{}}
151 int k1 = f(&f); // expected-error {{no match}}
152 int k2 = f(&f<int>);
153 int k3 = f(&g<int>); // expected-error {{no match}}
155 void h() {
156 (void)&f; // expected-error {{address of overloaded function 'f' cannot be cast to type 'void'}}
157 (void)&f<int>;
158 (void)&g<int>; // expected-error {{address of overloaded function 'g' cannot be cast to type 'void'}}
160 &f; // expected-error {{reference to overloaded function could not be resolved}}
161 &f<int>; // expected-warning {{unused}}
162 &g<int>; // expected-error {{reference to overloaded function could not be resolved}}
165 struct S {
166 template<typename T> static int f(T);
167 template<typename T> static int g(T);
168 template<typename T> static int g(T, int);
169 } s;
171 int k4 = f(&s.f); // expected-error {{non-constant pointer to member}}
172 int k5 = f(&s.f<int>);
173 int k6 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
175 void i() {
176 (void)&s.f; // expected-error {{non-constant pointer to member}}
177 (void)&s.f<int>;
178 (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
180 &s.f; // expected-error {{non-constant pointer to member}}
181 &s.f<int>; // expected-warning {{unused}}
182 &s.g<int>; // expected-error {{non-constant pointer to member}}
185 struct T {
186 template<typename T> int f(T);
187 template<typename T> int g(T);
188 template<typename T> int g(T, int);
189 } t;
191 int k7 = f(&s.f); // expected-error {{non-constant pointer to member}}
192 int k8 = f(&s.f<int>);
193 int k9 = f(&s.g<int>); // expected-error {{non-constant pointer to member}}
195 void j() {
196 (void)&s.f; // expected-error {{non-constant pointer to member}}
197 (void)&s.f<int>;
198 (void)&s.g<int>; // expected-error {{non-constant pointer to member}}
200 &s.f; // expected-error {{non-constant pointer to member}}
201 &s.f<int>; // expected-warning {{unused}}
202 &s.g<int>; // expected-error {{non-constant pointer to member}}
205 #if __cplusplus >= 201103L
206 // Special case kicks in only if a template argument list is specified.
207 template<typename T=int> void with_default(); // expected-note +{{}}
208 int k10 = f(&with_default); // expected-error {{no matching function}}
209 int k11 = f(&with_default<>);
210 void k() {
211 (void)&with_default; // expected-error {{overloaded function}}
212 (void)&with_default<>;
213 &with_default; // expected-error {{overloaded function}}
214 &with_default<>; // expected-warning {{unused}}
216 #endif
219 namespace dr116 { // dr116: yes
220 template<int> struct A {};
221 template<int N> void f(A<N>) {} // expected-note {{previous}}
222 template<int M> void f(A<M>) {} // expected-error {{redefinition}}
223 template<typename T> void f(A<sizeof(T)>) {} // expected-note {{previous}}
224 template<typename U> void f(A<sizeof(U)>) {} // expected-error {{redefinition}}
227 // dr117: na
228 // dr118 is in its own file.
229 // dr119: na
230 // dr120: na
232 namespace dr121 { // dr121: yes
233 struct X {
234 template<typename T> struct Y {};
236 template<typename T> struct Z {
237 X::Y<T> x;
238 T::Y<T> y; // expected-error +{{}}
240 Z<X> z;
243 namespace dr122 { // dr122: yes
244 template<typename T> void f();
245 void g() { f<int>(); }
248 // dr123: na
249 // dr124: dup 201
251 // dr125: yes
252 struct dr125_A { struct dr125_B {}; }; // expected-note {{here}}
253 dr125_A::dr125_B dr125_C();
254 namespace dr125_B { dr125_A dr125_C(); }
255 namespace dr125 {
256 struct X {
257 friend dr125_A::dr125_B (::dr125_C)(); // ok
258 friend dr125_A (::dr125_B::dr125_C)(); // ok
259 friend dr125_A::dr125_B::dr125_C(); // expected-error {{did you mean the constructor name 'dr125_B'?}}
260 // expected-error@-1 {{missing exception specification}}
264 namespace dr126 { // dr126: partial
265 // FIXME: We do not yet generate correct code for this change:
266 // eg:
267 // catch (void*&) should catch void* but not int*
268 // catch (void*) and catch (void*const&) should catch both
269 // Likewise:
270 // catch (Base *&) should catch Base* but not Derived*
271 // catch (Base *) should catch both
272 // In each case, we emit the same code for both catches.
274 // The ABI does not let us represent the language rule in the unwind tables.
275 // So, when catching by non-const (or volatile) reference to pointer, we
276 // should compare the exception type to the caught type and only accept an
277 // exact match.
278 #if __cplusplus <= 201402L
279 struct C {};
280 struct D : C {};
281 struct E : private C { friend class A; friend class B; };
282 struct F : protected C {};
283 struct G : C {};
284 struct H : D, G {};
286 struct A {
287 virtual void cp() throw(C*);
288 virtual void dp() throw(C*);
289 virtual void ep() throw(C*); // expected-note {{overridden}}
290 virtual void fp() throw(C*); // expected-note {{overridden}}
291 virtual void gp() throw(C*);
292 virtual void hp() throw(C*); // expected-note {{overridden}}
294 virtual void cr() throw(C&);
295 virtual void dr() throw(C&);
296 virtual void er() throw(C&); // expected-note {{overridden}}
297 virtual void fr() throw(C&); // expected-note {{overridden}}
298 virtual void gr() throw(C&);
299 virtual void hr() throw(C&); // expected-note {{overridden}}
301 virtual void pv() throw(void*);
303 #if __cplusplus >= 201103L
304 virtual void np() throw(C*);
305 virtual void npm() throw(int C::*);
306 virtual void nr() throw(C*&); // expected-note {{overridden}}
307 virtual void ncr() throw(C*const&);
308 #endif
310 virtual void ref1() throw(C *const&);
311 virtual void ref2() throw(C *);
313 virtual void v() throw(int);
314 virtual void w() throw(const int);
315 virtual void x() throw(int*); // expected-note {{overridden}}
316 virtual void y() throw(const int*);
317 virtual void z() throw(int); // expected-note {{overridden}}
319 struct B : A {
320 virtual void cp() throw(C*);
321 virtual void dp() throw(D*);
322 virtual void ep() throw(E*); // expected-error {{more lax}}
323 virtual void fp() throw(F*); // expected-error {{more lax}}
324 virtual void gp() throw(G*);
325 virtual void hp() throw(H*); // expected-error {{more lax}}
327 virtual void cr() throw(C&);
328 virtual void dr() throw(D&);
329 virtual void er() throw(E&); // expected-error {{more lax}}
330 virtual void fr() throw(F&); // expected-error {{more lax}}
331 virtual void gr() throw(G&);
332 virtual void hr() throw(H&); // expected-error {{more lax}}
334 virtual void pv() throw(C*);
336 #if __cplusplus >= 201103L
337 using nullptr_t = decltype(nullptr);
338 virtual void np() throw(nullptr_t);
339 virtual void npm() throw(nullptr_t&);
340 virtual void nr() throw(nullptr_t); // expected-error {{more lax}}
341 virtual void ncr() throw(nullptr_t);
342 #endif
344 virtual void ref1() throw(D *const &);
345 virtual void ref2() throw(D *);
347 virtual void v() throw(const int);
348 virtual void w() throw(int);
349 virtual void x() throw(const int*); // expected-error {{more lax}}
350 virtual void y() throw(int*); // ok
351 virtual void z() throw(long); // expected-error {{more lax}}
353 #else
354 void f() throw(int); // expected-error {{ISO C++17 does not allow}} expected-note {{use 'noexcept}}
355 #endif
358 namespace dr127 { // dr127: yes
359 __extension__ typedef __decltype(sizeof(0)) size_t;
360 template<typename T> struct A {
361 A() { throw 0; }
362 void *operator new(size_t, const char * = 0);
363 void operator delete(void *, const char *) { T::error; } // expected-error 2{{no members}}
364 void operator delete(void *) { T::error; }
366 A<void> *p = new A<void>; // expected-note {{instantiat}}
367 A<int> *q = new ("") A<int>; // expected-note {{instantiat}}
370 namespace dr128 { // dr128: yes
371 enum E1 { e1 } x = e1;
372 enum E2 { e2 } y = static_cast<E2>(x), z = static_cast<E2>(e1);
375 // dr129: dup 616
376 // dr130: na
378 namespace dr131 { // dr131: sup P1949
379 const char *a_with_\u0e8c = "\u0e8c";
380 const char *b_with_\u0e8d = "\u0e8d";
381 const char *c_with_\u0e8e = "\u0e8e";
384 namespace dr132 { // dr132: no
385 void f() {
386 extern struct {} x; // ok
387 extern struct S {} y; // FIXME: This is invalid.
389 static enum { E } e;
392 // dr133: dup 87
393 // dr134: na
395 namespace dr135 { // dr135: yes
396 struct A {
397 A f(A a) { return a; }
398 friend A g(A a) { return a; }
399 static A h(A a) { return a; }
403 namespace dr136 { // dr136: 3.4
404 void f(int, int, int = 0); // expected-note {{previous declaration is here}}
405 void g(int, int, int); // expected-note {{previous declaration is here}}
406 struct A {
407 friend void f(int, int = 0, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
408 friend void g(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
409 friend void h(int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be a definition}}
410 friend void i(int, int, int = 0) {} // expected-note {{previous declaration is here}}
411 friend void j(int, int, int = 0) {}
412 operator int();
414 void i(int, int, int); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
415 void q() {
416 j(A(), A()); // ok, has default argument
418 extern "C" void k(int, int, int, int); // expected-note 2{{previous declaration is here}}
419 namespace NSA {
420 struct A {
421 friend void dr136::k(int, int, int, int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
424 namespace NSB {
425 struct A {
426 friend void dr136::k(int, int, int = 0, int); // expected-error {{missing default argument on parameter}} expected-error {{must be the only declaration}}
429 struct B {
430 void f(int); // expected-note {{previous declaration is here}}
432 struct C {
433 friend void B::f(int = 0); // expected-error {{friend declaration specifying a default argument must be the only declaration}}
437 namespace dr137 { // dr137: yes
438 extern void *p;
439 extern const void *cp;
440 extern volatile void *vp;
441 extern const volatile void *cvp;
442 int *q = static_cast<int*>(p);
443 int *qc = static_cast<int*>(cp); // expected-error {{casts away qualifiers}}
444 int *qv = static_cast<int*>(vp); // expected-error {{casts away qualifiers}}
445 int *qcv = static_cast<int*>(cvp); // expected-error {{casts away qualifiers}}
446 const int *cq = static_cast<const int*>(p);
447 const int *cqc = static_cast<const int*>(cp);
448 const int *cqv = static_cast<const int*>(vp); // expected-error {{casts away qualifiers}}
449 const int *cqcv = static_cast<const int*>(cvp); // expected-error {{casts away qualifiers}}
450 const volatile int *cvq = static_cast<const volatile int*>(p);
451 const volatile int *cvqc = static_cast<const volatile int*>(cp);
452 const volatile int *cvqv = static_cast<const volatile int*>(vp);
453 const volatile int *cvqcv = static_cast<const volatile int*>(cvp);
456 namespace dr139 { // dr139: yes
457 namespace example1 {
458 typedef int f; // expected-note {{previous}}
459 struct A {
460 friend void f(A &); // expected-error {{different kind of symbol}}
464 namespace example2 {
465 typedef int f;
466 namespace N {
467 struct A {
468 friend void f(A &);
469 operator int();
470 void g(A a) { int i = f(a); } // ok, f is typedef not friend function
476 namespace dr140 { // dr140: yes
477 void f(int *const) {} // expected-note {{previous}}
478 void f(int[3]) {} // expected-error {{redefinition}}
479 void g(const int);
480 void g(int n) { n = 2; }
483 namespace dr141 { // dr141: yes
484 template<typename T> void f();
485 template<typename T> struct S { int n; }; // expected-note {{'::dr141::S<int>::n' declared here}}
486 struct A : S<int> {
487 template<typename T> void f();
488 template<typename T> struct S {};
489 } a;
490 struct B : S<int> {} b;
491 void g() {
492 a.f<int>();
493 (void)a.S<int>::n; // expected-error {{no member named 'n' in 'dr141::A::S<int>'; did you mean '::dr141::S<int>::n'?}}
494 #if __cplusplus < 201103L
495 // expected-error@-2 {{ambiguous}}
496 // expected-note@-11 {{lookup from the current scope}}
497 // expected-note@-9 {{lookup in the object type}}
498 #endif
499 b.f<int>(); // expected-error {{no member}} expected-error +{{}}
500 (void)b.S<int>::n;
502 template<typename T> struct C {
503 T t;
504 void g() {
505 t.f<int>(); // expected-error {{use 'template'}}
507 void h() {
508 (void)t.S<int>::n; // ok
510 void i() {
511 (void)t.S<int>(); // ok!
514 void h() { C<B>().h(); } // ok
515 struct X {
516 template<typename T> void S();
518 void i() { C<X>().i(); } // ok!!
521 namespace dr142 { // dr142: yes
522 class B { // expected-note +{{here}}
523 public:
524 int mi; // expected-note +{{here}}
525 static int si; // expected-note +{{here}}
527 class D : private B { // expected-note +{{here}}
529 class DD : public D {
530 void f();
532 void DD::f() {
533 mi = 3; // expected-error {{private member}}
534 si = 3; // expected-error {{private member}}
535 B b_old; // expected-error {{private member}}
536 dr142::B b;
537 b.mi = 3;
538 b.si = 3;
539 B::si = 3; // expected-error {{private member}}
540 dr142::B::si = 3;
541 B *bp1_old = this; // expected-error {{private member}} expected-error {{private base class}}
542 dr142::B *bp1 = this; // expected-error {{private base class}}
543 B *bp2_old = (B*)this; // expected-error 2{{private member}}
544 dr142::B *bp2 = (dr142::B*)this;
545 bp2->mi = 3;
549 namespace dr143 { // dr143: yes
550 namespace A { struct X; }
551 namespace B { void f(A::X); }
552 namespace A {
553 struct X { friend void B::f(X); };
555 void g(A::X x) {
556 f(x); // expected-error {{undeclared identifier 'f'}}
560 namespace dr145 { // dr145: yes
561 void f(bool b) {
562 #if __cplusplus <= 201402L
563 ++b; // expected-warning {{deprecated}}
564 b++; // expected-warning {{deprecated}}
565 #else
566 ++b; // expected-error {{increment}}
567 b++; // expected-error {{increment}}
568 #endif
572 namespace dr147 { // dr147: yes
573 namespace example1 {
574 template<typename> struct A {
575 template<typename T> A(T);
577 // Per core issue 1435, this is ill-formed because A<int>::A<int> does not
578 // name the injected-class-name. (A<int>::A does, though.)
579 template<> template<> A<int>::A<int>(int) {} // expected-error {{out-of-line constructor for 'A' cannot have template arguments}}
580 template<> template<> A<float>::A(float) {}
582 namespace example2 {
583 struct A { A(); };
584 struct B : A { B(); };
585 A::A a1; // expected-error {{is a constructor}}
586 B::A a2;
588 namespace example3 {
589 template<typename> struct A {
590 template<typename T> A(T);
591 static A a;
593 template<> A<int>::A<int>(A<int>::a); // expected-error {{is a constructor}}
597 namespace dr148 { // dr148: yes
598 struct A { int A::*p; };
599 int check1[__is_pod(int(A::*)) ? 1 : -1];
600 int check2[__is_pod(A) ? 1 : -1];
603 // dr149: na
605 namespace dr151 { // dr151: yes
606 struct X {};
607 typedef int X::*p;
608 #if __cplusplus < 201103L
609 #define fold(x) (__builtin_constant_p(0) ? (x) : (x))
610 #else
611 #define fold
612 #endif
613 int check[fold(p() == 0) ? 1 : -1];
614 #undef fold
617 namespace dr152 { // dr152: yes
618 struct A {
619 A(); // expected-note 0-2{{not viable}}
620 explicit A(const A&); // expected-note 1-2{{not a candidate}}
622 A a1 = A();
623 #if __cplusplus <= 201402L
624 // expected-error@-2 {{no matching constructor}}
625 #endif
626 A a2((A()));
628 A &f();
629 A a3 = f(); // expected-error {{no matching constructor}}
630 A a4(f());
633 // dr153: na
635 namespace dr154 { // dr154: yes
636 union { int a; }; // expected-error {{must be declared 'static'}}
637 namespace {
638 union { int b; };
640 static union { int c; };
643 namespace dr155 { // dr155: dup 632
644 struct S { int n; } s = { { 1 } }; // expected-warning {{braces around scalar initializer}}
647 // dr158 is in its own file.
649 namespace dr159 { // dr159: 3.5
650 namespace X { void f(); }
651 void f();
652 void dr159::f() {} // expected-warning {{extra qualification}}
653 void dr159::X::f() {}
656 // dr160: na
658 namespace dr161 { // dr161: yes
659 class A {
660 protected:
661 struct B { int n; } b; // expected-note 2{{here}}
662 static B bs;
663 void f(); // expected-note {{here}}
664 static void sf();
666 struct C : A {};
667 struct D : A {
668 void g(C c) {
669 (void)b.n;
670 B b1;
671 C::B b2; // ok, accessible as a member of A
672 (void)&C::b; // expected-error {{protected}}
673 (void)&C::bs;
674 (void)c.b; // expected-error {{protected}}
675 (void)c.bs;
676 f();
677 sf();
678 c.f(); // expected-error {{protected}}
679 c.sf();
680 A::f();
681 D::f();
682 A::sf();
683 C::sf();
684 D::sf();
689 namespace dr162 { // dr162: no
690 struct A {
691 char &f(char);
692 static int &f(int);
694 void g() {
695 int &a = (&A::f)(0); // FIXME: expected-error {{could not be resolved}}
696 char &b = (&A::f)('0'); // expected-error {{could not be resolved}}
700 int &c = (&A::f)(0); // FIXME: expected-error {{could not be resolved}}
701 char &d = (&A::f)('0'); // expected-error {{could not be resolved}}
704 // dr163: na
706 namespace dr164 { // dr164: yes
707 void f(int);
708 template <class T> int g(T t) { return f(t); }
710 enum E { e };
711 int f(E);
713 int k = g(e);
716 namespace dr165 { // dr165: no
717 namespace N {
718 struct A { friend struct B; };
719 void f() { void g(); }
721 // FIXME: dr1477 says this is ok, dr165 says it's ill-formed
722 struct N::B {};
723 // FIXME: dr165 says this is ill-formed, but the argument in dr1477 says it's ok
724 void N::g() {}
727 namespace dr166 { // dr166: yes
728 namespace A { class X; }
730 template<typename T> int f(T t) { return t.n; }
731 int g(A::X);
732 template<typename T> int h(T t) { return t.n; } // expected-error {{private}}
733 int i(A::X);
735 namespace A {
736 class X {
737 friend int f<X>(X);
738 friend int dr166::g(X);
739 friend int h(X);
740 friend int i(X);
741 int n; // expected-note 2{{here}}
744 int h(X x) { return x.n; }
745 int i(X x) { return x.n; }
748 template int f(A::X);
749 int g(A::X x) { return x.n; }
750 template int h(A::X); // expected-note {{instantiation}}
751 int i(A::X x) { return x.n; } // expected-error {{private}}
754 // dr167: sup 1012
756 namespace dr168 { // dr168: no
757 extern "C" typedef int (*p)();
758 extern "C++" typedef int (*q)();
759 struct S {
760 static int f();
762 p a = &S::f; // FIXME: this should fail.
763 q b = &S::f;
766 namespace dr169 { // dr169: yes
767 template<typename> struct A { int n; };
768 struct B {
769 template<typename> struct C;
770 template<typename> void f();
771 template<typename> static int n; // expected-error 0-1{{extension}}
773 struct D : A<int>, B {
774 using A<int>::n;
775 using B::C<int>; // expected-error {{using declaration cannot refer to a template specialization}}
776 using B::f<int>; // expected-error {{using declaration cannot refer to a template specialization}}
777 using B::n<int>; // expected-error {{using declaration cannot refer to a template specialization}}
781 namespace { // dr171: yes
782 int dr171a;
784 int dr171b; // expected-note {{here}}
785 namespace dr171 {
786 extern "C" void dr171a();
787 extern "C" void dr171b(); // expected-error {{conflicts}}
790 namespace dr172 { // dr172: yes
791 enum { zero };
792 int check1[-1 < zero ? 1 : -1];
794 enum { x = -1, y = (unsigned int)-1 };
795 int check2[sizeof(x) > sizeof(int) ? 1 : -1];
797 enum { a = (unsigned int)-1 / 2 };
798 int check3a[sizeof(a) == sizeof(int) ? 1 : -1];
799 int check3b[-a < 0 ? 1 : -1];
801 enum { b = (unsigned int)-1 / 2 + 1 };
802 int check4a[sizeof(b) == sizeof(unsigned int) ? 1 : -1];
803 int check4b[-b > 0 ? 1 : -1];
805 enum { c = (unsigned long)-1 / 2 };
806 int check5a[sizeof(c) == sizeof(long) ? 1 : -1];
807 int check5b[-c < 0 ? 1 : -1];
809 enum { d = (unsigned long)-1 / 2 + 1 };
810 int check6a[sizeof(d) == sizeof(unsigned long) ? 1 : -1];
811 int check6b[-d > 0 ? 1 : -1];
813 enum { e = (unsigned long long)-1 / 2 }; // expected-error 0-1{{extension}}
814 int check7a[sizeof(e) == sizeof(long) ? 1 : -1]; // expected-error 0-1{{extension}}
815 int check7b[-e < 0 ? 1 : -1];
817 enum { f = (unsigned long long)-1 / 2 + 1 }; // expected-error 0-1{{extension}}
818 int check8a[sizeof(f) == sizeof(unsigned long) ? 1 : -1]; // expected-error 0-1{{extension}}
819 int check8b[-f > 0 ? 1 : -1];
822 namespace dr173 { // dr173: yes
823 int check[('0' + 1 == '1' && '0' + 2 == '2' && '0' + 3 == '3' &&
824 '0' + 4 == '4' && '0' + 5 == '5' && '0' + 6 == '6' &&
825 '0' + 7 == '7' && '0' + 8 == '8' && '0' + 9 == '9') ? 1 : -1];
828 // dr174: sup 1012
830 namespace dr175 { // dr175: yes
831 struct A {}; // expected-note {{here}}
832 struct B : private A {}; // expected-note {{constrained by private inheritance}}
833 struct C : B {
834 A a; // expected-error {{private}}
835 dr175::A b;
839 namespace dr176 { // dr176: yes
840 template<typename T> class Y;
841 template<> class Y<int> {
842 void f() {
843 typedef Y A; // expected-note {{here}}
844 typedef Y<char> A; // expected-error {{different types ('Y<char>' vs 'Y<int>')}}
848 template<typename T> struct Base {}; // expected-note 2{{found}}
849 template<typename T> struct Derived : public Base<T> {
850 void f() {
851 typedef typename Derived::template Base<T> A;
852 typedef typename Derived::Base A;
855 template struct Derived<int>;
857 template<typename T> struct Derived2 : Base<int>, Base<char> {
858 typename Derived2::Base b; // expected-error {{found in multiple base classes}}
859 typename Derived2::Base<double> d;
862 template<typename T> class X { // expected-note {{here}}
863 X *p1;
864 X<T> *p2;
865 X<int> *p3;
866 dr176::X *p4; // expected-error {{requires template arguments}}
870 namespace dr177 { // dr177: yes
871 struct B {};
872 struct A {
873 A(A &); // expected-note 0-1{{not viable: expects an lvalue}}
874 A(const B &); // expected-note 0-1{{not viable: no known conversion from 'A' to}}
876 B b;
877 A a = b;
878 #if __cplusplus <= 201402L
879 // expected-error@-2 {{no viable constructor copying variable}}
880 #endif
882 struct C { C(C&); }; // expected-note {{not viable: expects an lvalue for 1st argument}}
883 struct D : C {};
884 struct E { operator D(); };
885 E e;
886 C c = e; // expected-error {{no viable constructor copying variable of type 'D'}}
889 namespace dr178 { // dr178: yes
890 int check[int() == 0 ? 1 : -1];
891 #if __cplusplus >= 201103L
892 static_assert(int{} == 0, "");
893 struct S { int a, b; };
894 static_assert(S{1}.b == 0, "");
895 struct T { constexpr T() : n() {} int n; };
896 static_assert(T().n == 0, "");
897 struct U : S { constexpr U() : S() {} };
898 static_assert(U().b == 0, "");
899 #endif
902 namespace dr179 { // dr179: yes
903 void f();
904 int n = &f - &f; // expected-error {{arithmetic on pointers to the function type 'void ()'}}
907 namespace dr180 { // dr180: yes
908 template<typename T> struct X : T, T::some_base {
909 X() : T::some_type_that_might_be_T(), T::some_base() {}
910 friend class T::some_class;
911 void f() {
912 enum T::some_enum e;
917 namespace dr181 { // dr181: yes
918 namespace X {
919 template <template X<class T> > struct A { }; // expected-error +{{}}
920 template <template X<class T> > void f(A<X>) { } // expected-error +{{}}
923 namespace Y {
924 template <template <class T> class X> struct A { };
925 template <template <class T> class X> void f(A<X>) { }
929 namespace dr182 { // dr182: yes
930 template <class T> struct C {
931 void f();
932 void g();
935 template <class T> void C<T>::f() {}
936 template <class T> void C<T>::g() {}
938 class A {
939 class B {};
940 void f();
943 template void C<A::B>::f();
944 template <> void C<A::B>::g();
946 void A::f() {
947 C<B> cb;
948 cb.f();
952 namespace dr183 { // dr183: sup 382
953 template<typename T> struct A {};
954 template<typename T> struct B {
955 typedef int X;
957 template<> struct A<int> {
958 #if __cplusplus <= 199711
959 typename B<int>::X x; // expected-error {{'typename' occurs outside of a template}}
960 #else
961 typename B<int>::X x;
962 #endif
966 namespace dr184 { // dr184: yes
967 template<typename T = float> struct B {};
969 template<template<typename TT = float> class T> struct A {
970 void f();
971 void g();
974 template<template<typename TT> class T> void A<T>::f() { // expected-note {{here}}
975 T<> t; // expected-error {{too few template arguments}}
978 template<template<typename TT = char> class T> void A<T>::g() {
979 T<> t;
980 typedef T<> X;
981 typedef T<char> X;
984 void h() { A<B>().g(); }
987 // dr185 FIXME: add codegen test
989 namespace dr187 { // dr187: sup 481
990 const int Z = 1;
991 template<int X = Z, int Z = X> struct A;
992 typedef A<> T;
993 typedef A<1, 1> T;
996 namespace dr188 { // dr188: yes
997 char c[10];
998 int check[sizeof(0, c) == 10 ? 1 : -1];
1001 // dr190 FIXME: add codegen test for tbaa
1003 int dr191_j;
1004 namespace dr191 { // dr191: yes
1005 namespace example1 {
1006 struct outer {
1007 static int i;
1008 struct inner {
1009 void f() {
1010 struct local {
1011 void g() {
1012 i = 5;
1020 namespace example2 {
1021 struct S {
1022 void f() {
1023 struct local2 {
1024 void g() {
1025 dr191_j = 5;
1033 // dr193 FIXME: add codegen test
1035 namespace dr194 { // dr194: yes
1036 struct A {
1037 A();
1038 void A(); // expected-error {{constructor cannot have a return type}}
1040 struct B {
1041 void B(); // expected-error {{constructor cannot have a return type}}
1042 B();
1044 struct C {
1045 inline explicit C(int) {}
1049 namespace dr195 { // dr195: yes
1050 void f();
1051 int *p = (int*)&f; // expected-error 0-1{{extension}}
1052 void (*q)() = (void(*)())&p; // expected-error 0-1{{extension}}
1055 namespace dr197 { // dr197: yes
1056 char &f(char);
1058 template <class T> void g(T t) {
1059 char &a = f(1);
1060 char &b = f(T(1)); // expected-error {{unrelated type 'int'}}
1061 char &c = f(t); // expected-error {{unrelated type 'int'}}
1064 void f(int);
1066 enum E { e };
1067 int &f(E);
1069 void h() {
1070 g('a');
1071 g(2);
1072 g(e); // expected-note {{in instantiation of}}
1076 namespace dr198 { // dr198: yes
1077 struct A {
1078 int n;
1079 struct B {
1080 int m[sizeof(n)];
1081 #if __cplusplus < 201103L
1082 // expected-error@-2 {{invalid use of non-static data member}}
1083 #endif
1084 int f() { return n; }
1085 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'B'}}
1087 struct C;
1088 struct D;
1090 struct A::C {
1091 int m[sizeof(n)];
1092 #if __cplusplus < 201103L
1093 // expected-error@-2 {{invalid use of non-static data member}}
1094 #endif
1095 int f() { return n; }
1096 // expected-error@-1 {{use of non-static data member 'n' of 'A' from nested type 'C'}}
1098 struct A::D : A {
1099 int m[sizeof(n)];
1100 #if __cplusplus < 201103L
1101 // expected-error@-2 {{invalid use of non-static data member}}
1102 #endif
1103 int f() { return n; }
1107 // dr199 FIXME: add codegen test