Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr5xx.cpp
bloba3563481eac68e81f8e6e16d8cfafe03aa149708
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 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
8 // FIXME: This is included to avoid a diagnostic with no source location
9 // pointing at the implicit operator new. We can't match such a diagnostic
10 // with -verify.
11 __extension__ typedef __SIZE_TYPE__ size_t;
12 void *operator new(size_t); // expected-error 0-1{{missing exception spec}} expected-note{{candidate}}
13 #if __cplusplus > 201402L
14 namespace std {
15 enum class align_val_t : size_t {};
17 void *operator new(size_t, std::align_val_t); // expected-note{{candidate}}
18 #endif
20 namespace dr500 { // dr500: dup 372
21 class D;
22 class A {
23 class B;
24 class C;
25 friend class D;
27 class A::B {};
28 class A::C : public A::B {};
29 class D : public A::B {};
32 namespace dr501 { // dr501: yes
33 struct A {
34 friend void f() {}
35 void g() {
36 void (*p)() = &f; // expected-error {{undeclared identifier}}
41 namespace dr502 { // dr502: yes
42 struct Q {};
43 template<typename T> struct A {
44 enum E { e = 1 };
45 void q1() { f(e); }
46 void q2() { Q arr[sizeof(E)]; f(arr); }
47 void q3() { Q arr[e]; f(arr); }
48 void sanity() { Q arr[1]; f(arr); } // expected-error {{undeclared identifier 'f'}}
50 int f(A<int>::E);
51 template<int N> int f(Q (&)[N]);
52 template struct A<int>;
55 namespace dr505 { // dr505: yes
56 const char *exts = "\e\(\{\[\%"; // expected-error 5{{use of non-standard escape}}
57 const char *unknown = "\Q"; // expected-error {{unknown escape sequence}}
60 namespace dr506 { // dr506: yes
61 struct NonPod { ~NonPod(); };
62 void f(...);
63 void g(NonPod np) { f(np); } // expected-error {{cannot pass}}
66 // FIXME: Add tests here once DR260 is resolved.
67 // dr507: dup 260
69 // dr508: na
70 // dr509: na
71 // dr510: na
73 namespace dr512 { // dr512: yes
74 struct A {
75 A(int);
77 union U { A a; };
78 #if __cplusplus < 201103L
79 // expected-error@-2 {{has a non-trivial default constructor}}
80 // expected-note@-6 {{no default constructor}}
81 // expected-note@-6 {{suppressed by user-declared constructor}}
82 #endif
85 // dr513: na
87 namespace dr514 { // dr514: yes
88 namespace A { extern int x, y; }
89 int A::x = y;
92 namespace dr515 { // dr515: sup 1017
93 // FIXME: dr1017 reverses the wording of dr515, but the current draft has
94 // dr515's wording, with a different fix for dr1017.
96 struct X { int n; };
97 template<typename T> struct Y : T {
98 int f() { return X::n; }
100 int k = Y<X>().f();
102 struct A { int a; };
103 struct B { void f() { int k = sizeof(A::a); } };
104 #if __cplusplus < 201103L
105 // expected-error@-2 {{invalid use of non-static data member}}
106 #endif
109 // dr516: na
111 namespace dr517 { // dr517: no
112 // This is NDR, but we should diagnose it anyway.
113 template<typename T> struct S {};
114 template<typename T> int v = 0; // expected-error 0-1{{extension}}
116 template struct S<int*>;
117 template int v<int*>;
119 S<char&> s;
120 int k = v<char&>;
122 // FIXME: These are both ill-formed.
123 template<typename T> struct S<T*> {};
124 template<typename T> int v<T*> = 0; // expected-error 0-1{{extension}}
126 // FIXME: These are both ill-formed.
127 template<typename T> struct S<T&> {};
128 template<typename T> int v<T&> = 0; // expected-error 0-1{{extension}}
131 namespace dr518 { // dr518: yes c++11
132 enum E { e, };
133 #if __cplusplus < 201103L
134 // expected-error@-2 {{C++11 extension}}
135 #endif
138 namespace dr519 { // dr519: yes
139 // FIXME: Add a codegen test.
140 #if __cplusplus >= 201103L
141 #define fold(x) (__builtin_constant_p(x) ? (x) : (x))
142 int test[fold((int*)(void*)0) ? -1 : 1];
143 #undef fold
144 #endif
147 // dr520: na
149 // dr521: no
150 // FIXME: The wording here is broken. It's not reasonable to expect a
151 // diagnostic here. Once the relevant DR gets a number, mark this as a dup.
153 namespace dr522 { // dr522: yes
154 struct S {};
155 template<typename T> void b1(volatile T &);
156 template<typename T> void b2(volatile T * const *);
157 template<typename T> void b2(volatile T * const S::*);
158 template<typename T> void b2(volatile T * const S::* const *);
159 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}}
161 template<typename T> struct Base {};
162 struct Derived : Base<int> {};
163 template<typename T> void b3(Base<T>);
164 template<typename T> void b3(Base<T> *);
166 void test(int n, const int cn, int **p, int *S::*pm) {
167 int *a[3], *S::*am[3];
168 const Derived cd = Derived();
169 Derived d[3];
171 b1(n);
172 b1(cn);
173 b2(p);
174 b2(pm);
175 b2(a);
176 b2(am);
177 b2a(am); // expected-error {{no matching function}}
178 b3(d);
179 b3(cd);
183 namespace dr524 { // dr524: yes
184 template<typename T> void f(T a, T b) { operator+(a, b); } // expected-error {{call}}
186 struct S {};
187 void operator+(S, S);
188 template void f(S, S);
190 namespace N { struct S {}; }
191 void operator+(N::S, N::S); // expected-note {{should be declared}}
192 template void f(N::S, N::S); // expected-note {{instantiation}}
195 namespace dr525 { // dr525: yes
196 namespace before {
197 // Note, the example was correct prior to the change; instantiation is
198 // required for cases like this:
199 template <class T> struct D { operator T*(); };
200 void g(D<double> ppp) {
201 delete ppp;
204 namespace after {
205 template <class T> struct D { typename T::error e; }; // expected-error {{prior to '::'}}
206 void g(D<double> *ppp) {
207 delete ppp; // expected-note {{instantiation of}}
212 namespace dr526 { // dr526: yes
213 template<int> struct S {};
214 template<int N> void f1(S<N> s);
215 template<int N> void f2(S<(N)> s); // expected-note {{couldn't infer}}
216 template<int N> void f3(S<+N> s); // expected-note {{couldn't infer}}
217 template<int N> void g1(int (&)[N]);
218 template<int N> void g2(int (&)[(N)]); // expected-note {{couldn't infer}}
219 template<int N> void g3(int (&)[+N]); // expected-note {{couldn't infer}}
221 void test(int (&a)[3], S<3> s) {
222 f1(s);
223 f2(s); // expected-error {{no matching}}
224 f3(s); // expected-error {{no matching}}
225 g1(a);
226 g2(a); // expected-error {{no matching}}
227 g3(a); // expected-error {{no matching}}
230 template<int N> struct X {
231 typedef int type;
232 X<N>::type v1;
233 X<(N)>::type v2;
234 X<+N>::type v3;
235 #if __cplusplus <= 201703L
236 // expected-error@-3 {{implicit 'typename' is a C++20 extension}}
237 // expected-error@-3 {{implicit 'typename' is a C++20 extension}}
238 #endif
242 namespace dr527 { // dr527: na
243 // This DR is meaningless. It removes a required diagnostic from the case
244 // where a not-externally-visible object is odr-used but not defined, which
245 // requires a diagnostic for a different reason.
246 extern struct { int x; } a; // FIXME: We should reject this, per dr389.
247 static struct { int x; } b;
248 extern "C" struct { int x; } c;
249 namespace { extern struct { int x; } d; }
250 typedef struct { int x; } *P;
251 struct E { static P e; }; // FIXME: We should reject this, per dr389.
252 namespace { struct F { static P f; }; }
254 int ax = a.x, bx = b.x, cx = c.x, dx = d.x, ex = E::e->x, fx = F::f->x;
257 namespace dr530 { // dr530: yes
258 template<int*> struct S { enum { N = 1 }; };
259 template<void(*)()> struct T { enum { N = 1 }; };
260 int n;
261 void f();
262 int a[S<&n>::N];
263 int b[T<&f>::N];
266 namespace dr531 { // dr531: partial
267 namespace good {
268 template<typename T> struct A {
269 void f(T) { T::error; }
270 template<typename U> void g(T, U) { T::error; }
271 struct B { typename T::error error; };
272 template<typename U> struct C { typename T::error error; };
273 static T n;
275 template<typename T> T A<T>::n = T::error;
277 template<> void A<int>::f(int) {}
278 template<> template<typename U> void A<int>::g(int, U) {}
279 template<> struct A<int>::B {};
280 template<> template<typename U> struct A<int>::C {};
281 template<> int A<int>::n = 0;
283 void use(A<int> a) {
284 a.f(a.n);
285 a.g(0, 0);
286 A<int>::B b;
287 A<int>::C<int> c;
290 template<> struct A<char> {
291 void f(char);
292 template<typename U> void g(char, U);
293 struct B;
294 template<typename U> struct C;
295 static char n;
298 void A<char>::f(char) {}
299 template<typename U> void A<char>::g(char, U) {}
300 struct A<char>::B {};
301 template<typename U> struct A<char>::C {};
302 char A<char>::n = 0;
305 namespace bad {
306 template<typename T> struct A {
307 void f(T) { T::error; }
308 template<typename U> void g(T, U) { T::error; }
309 struct B { typename T::error error; };
310 template<typename U> struct C { typename T::error error; }; // expected-note {{here}}
311 static T n;
313 template<typename T> T A<T>::n = T::error;
315 void A<int>::f(int) {} // expected-error {{requires 'template<>'}}
316 template<typename U> void A<int>::g(int, U) {} // expected-error {{should be empty}}
317 struct A<int>::B {}; // expected-error {{requires 'template<>'}}
318 template<typename U> struct A<int>::C {}; // expected-error {{should be empty}} expected-error {{different kind of symbol}}
319 int A<int>::n = 0; // expected-error {{requires 'template<>'}}
321 template<> struct A<char> { // expected-note 2{{here}}
322 void f(char);
323 template<typename U> void g(char, U);
324 struct B; // expected-note {{here}}
325 template<typename U> struct C;
326 static char n;
329 template<> void A<char>::f(char) {} // expected-error {{no function template matches}}
330 // FIXME: This is ill-formed; -pedantic-errors should reject.
331 template<> template<typename U> void A<char>::g(char, U) {} // expected-warning {{extraneous template parameter list}}
332 template<> struct A<char>::B {}; // expected-error {{extraneous 'template<>'}} expected-error {{does not specialize}}
333 // FIXME: This is ill-formed; -pedantic-errors should reject.
334 template<> template<typename U> struct A<char>::C {}; // expected-warning {{extraneous template parameter list}}
335 template<> char A<char>::n = 0; // expected-error {{extraneous 'template<>'}}
338 namespace nested {
339 template<typename T> struct A {
340 template<typename U> struct B;
342 template<> template<typename U> struct A<int>::B {
343 void f();
344 void g();
345 template<typename V> void h();
346 template<typename V> void i();
348 template<> template<typename U> void A<int>::B<U>::f() {}
349 template<typename U> void A<int>::B<U>::g() {} // expected-error {{should be empty}}
351 template<> template<typename U> template<typename V> void A<int>::B<U>::h() {}
352 template<typename U> template<typename V> void A<int>::B<U>::i() {} // expected-error {{should be empty}}
354 #if __cplusplus <= 201703L
355 // FIXME: All of those declarations shouldn't crash in C++20 mode.
356 template<> template<> void A<int>::B<int>::f() {}
357 template<> template<> template<typename V> void A<int>::B<int>::h() {}
358 template<> template<> template<> void A<int>::B<int>::h<int>() {}
360 template<> void A<int>::B<char>::f() {} // expected-error {{requires 'template<>'}}
361 template<> template<typename V> void A<int>::B<char>::h() {} // expected-error {{should be empty}}
362 #endif
366 // PR8130
367 namespace dr532 { // dr532: 3.5
368 struct A { };
370 template<class T> struct B {
371 template<class R> int &operator*(R&);
374 template<class T, class R> float &operator*(T&, R&);
375 void test() {
376 A a;
377 B<A> b;
378 int &ir = b * a;
382 // dr533: na
384 namespace dr534 { // dr534: yes
385 struct S {};
386 template<typename T> void operator+(S, T);
387 template<typename T> void operator+<T*>(S, T*) {} // expected-error {{function template partial spec}}
390 namespace dr535 { // dr535: yes
391 class X { private: X(const X&); };
392 struct A {
393 X x;
394 template<typename T> A(T&);
396 struct B : A {
397 X y;
398 B(volatile A&);
401 extern A a1;
402 A a2(a1); // ok, uses constructor template
404 extern volatile B b1;
405 B b2(b1); // ok, uses converting constructor
407 void f() { throw a1; }
409 #if __cplusplus >= 201103L
410 struct C {
411 constexpr C() : n(0) {}
412 template<typename T> constexpr C(T&t) : n(t.n == 0 ? throw 0 : 0) {}
413 int n;
415 constexpr C c() { return C(); }
416 // ok, copy is elided
417 constexpr C x = c();
418 #endif
421 // dr536: na
422 // dr537: na
423 // dr538: na
425 // dr539: yes
426 const dr539( // expected-error {{a type specifier is required}}
427 const a) { // expected-error {{unknown type name 'a'}}
428 const b; // expected-error {{a type specifier is required}}
429 new const; // expected-error {{expected a type}}
430 try {} catch (const n) {} // expected-error {{unknown type name 'n'}}
431 try {} catch (const) {} // expected-error {{expected a type}}
432 if (const n = 0) {} // expected-error {{a type specifier is required}}
433 switch (const n = 0) {} // expected-error {{a type specifier is required}}
434 while (const n = 0) {} // expected-error {{a type specifier is required}}
435 for (const n = 0; // expected-error {{a type specifier is required}}
436 const m = 0; ) {} // expected-error {{a type specifier is required}}
437 sizeof(const); // expected-error {{a type specifier is required}}
438 struct S {
439 const n; // expected-error {{a type specifier is required}}
440 operator const(); // expected-error {{expected a type}}
442 #if __cplusplus >= 201103L
443 int arr[3];
444 // FIXME: The extra braces here are to avoid the parser getting too
445 // badly confused when recovering here. We should fix this recovery.
446 { for (const n // expected-error {{unknown type name 'n'}} expected-note {{}}
447 : arr) ; {} } // expected-error +{{}}
448 (void) [](const) {}; // expected-error {{a type specifier is required}}
449 (void) [](const n) {}; // expected-error {{unknown type name 'n'}}
450 enum E : const {}; // expected-error {{expected a type}}
451 using T = const; // expected-error {{expected a type}}
452 auto f() -> const; // expected-error {{expected a type}}
453 #endif
456 namespace dr540 { // dr540: yes
457 typedef int &a;
458 typedef const a &a; // expected-warning {{has no effect}}
459 typedef const int &b;
460 typedef b &b;
461 typedef const a &c; // expected-note {{previous}} expected-warning {{has no effect}}
462 typedef const b &c; // expected-error {{different}} expected-warning {{has no effect}}
465 namespace dr541 { // dr541: yes
466 template<int> struct X { typedef int type; };
467 template<typename T> struct S {
468 int f(T);
470 int g(int);
471 T g(bool);
473 int h();
474 int h(T);
476 void x() {
477 // These are type-dependent expressions, even though we could
478 // determine that all calls have type 'int'.
479 X<sizeof(f(0))>::type a; // expected-error +{{}}
480 X<sizeof(g(0))>::type b; // expected-error +{{}}
481 X<sizeof(h(0))>::type b; // expected-error +{{}}
483 typename X<sizeof(f(0))>::type a;
484 typename X<sizeof(h(0))>::type b;
489 namespace dr542 { // dr542: yes
490 #if __cplusplus >= 201103L
491 // In C++20 A and B are no longer aggregates and thus the constructor is
492 // called, which fails.
493 struct A { A() = delete; int n; };
494 A a[32] = {}; // ok, constructor not called
495 #if __cplusplus > 201703L
496 // expected-error@-2 {{call to deleted constructor}}
497 // expected-note@-3 {{in implicit initialization}}
498 // expected-note@-5 {{marked deleted here}}
499 #endif
501 struct B {
502 int n;
503 private:
504 B() = default;
506 B b[32] = {}; // ok, constructor not called
507 #if __cplusplus > 201703L
508 // expected-error@-2 {{calling a private constructor}}
509 // expected-note@-5 {{declared private here}}
510 #endif
511 #endif
514 namespace dr543 { // dr543: yes
515 // In C++98+DR543, this is valid because value-initialization doesn't call a
516 // trivial default constructor, so we never notice that defining the
517 // constructor would be ill-formed.
519 // In C++11+DR543, this is ill-formed, because the default constructor is
520 // deleted, and value-initialization *does* call a deleted default
521 // constructor, even if it is trivial.
522 struct A {
523 const int n;
525 A a = A();
526 #if __cplusplus >= 201103L
527 // expected-error@-2 {{deleted}}
528 // expected-note@-5 {{would not be initialized}}
529 #endif
532 namespace dr544 { // dr544: yes
533 int *n;
535 template<class T> struct A { int n; };
536 template<class T> struct B : A<T> { int get(); };
537 template<> int B<int>::get() { return n; }
538 int k = B<int>().get();
541 namespace dr546 { // dr546: yes
542 template<typename T> struct A { void f(); };
543 template struct A<int>;
544 template<typename T> void A<T>::f() { T::error; }
547 namespace dr547 { // dr547: yes
548 template<typename T> struct X;
549 template<typename T> struct X<T() const> {};
550 template<typename T, typename C> X<T> f(T C::*) { return X<T>(); }
552 struct S { void f() const; };
553 X<void() const> x = f(&S::f);
556 namespace dr548 { // dr548: dup 482
557 template<typename T> struct S {};
558 template<typename T> void f() {}
559 template struct dr548::S<int>;
560 template void dr548::f<int>();
563 namespace dr551 { // dr551: yes c++11
564 // FIXME: This obviously should apply in C++98 mode too.
565 template<typename T> void f() {}
566 template inline void f<int>();
567 #if __cplusplus >= 201103L
568 // expected-error@-2 {{cannot be 'inline'}}
569 #endif
571 template<typename T> inline void g() {}
572 template inline void g<int>();
573 #if __cplusplus >= 201103L
574 // expected-error@-2 {{cannot be 'inline'}}
575 #endif
577 template<typename T> struct X {
578 void f() {}
580 template inline void X<int>::f();
581 #if __cplusplus >= 201103L
582 // expected-error@-2 {{cannot be 'inline'}}
583 #endif
586 namespace dr552 { // dr552: yes
587 template<typename T, typename T::U> struct X {};
588 struct Y { typedef int U; };
589 X<Y, 0> x;
592 struct dr553_class {
593 friend void *operator new(size_t, dr553_class);
595 namespace dr553 {
596 dr553_class c;
597 // Contrary to the apparent intention of the DR, operator new is not actually
598 // looked up with a lookup mechanism that performs ADL; the standard says it
599 // "is looked up in global scope", where it is not visible.
600 void *p = new (c) int; // expected-error {{no matching function}}
602 struct namespace_scope {
603 friend void *operator new(size_t, namespace_scope); // expected-error {{cannot be declared inside a namespace}}
607 // dr554: na
608 // dr556: na
610 namespace dr557 { // dr557: yes
611 template<typename T> struct S {
612 friend void f(S<T> *);
613 friend void g(S<S<T> > *);
615 void x(S<int> *p, S<S<int> > *q) {
616 f(p);
617 g(q);
621 namespace dr558 { // dr558: yes
622 wchar_t a = L'\uD7FF';
623 wchar_t b = L'\xD7FF';
624 wchar_t c = L'\uD800'; // expected-error {{invalid universal character}}
625 wchar_t d = L'\xD800';
626 wchar_t e = L'\uDFFF'; // expected-error {{invalid universal character}}
627 wchar_t f = L'\xDFFF';
628 wchar_t g = L'\uE000';
629 wchar_t h = L'\xE000';
632 template<typename> struct dr559 { typedef int T; dr559::T u; }; // dr559: yes
634 namespace dr561 { // dr561: yes
635 template<typename T> void f(int);
636 template<typename T> void g(T t) {
637 f<T>(t);
639 namespace {
640 struct S {};
641 template<typename T> static void f(S);
643 void h(S s) {
644 g(s);
648 // dr562: na
650 namespace dr564 { // dr564: yes
651 extern "C++" void f(int);
652 void f(int); // ok
653 extern "C++" { extern int n; }
654 int n; // ok
657 namespace dr565 { // dr565: yes
658 namespace N {
659 template<typename T> int f(T); // expected-note {{target}}
661 using N::f; // expected-note {{using}}
662 template<typename T> int f(T*);
663 template<typename T> void f(T);
664 template<typename T, int = 0> int f(T); // expected-error 0-1{{extension}}
665 template<typename T> int f(T, int = 0);
666 template<typename T> int f(T); // expected-error {{conflicts with}}
669 namespace dr566 { // dr566: yes
670 #if __cplusplus >= 201103L
671 int check[int(-3.99) == -3 ? 1 : -1];
672 #endif
675 // dr567: na
677 namespace dr568 { // dr568: yes c++11
678 // FIXME: This is a DR issue against C++98, so should probably apply there
679 // too.
680 struct x { int y; };
681 class trivial : x {
682 x y;
683 public:
684 int n;
686 int check_trivial[__is_trivial(trivial) ? 1 : -1];
688 struct std_layout {
689 std_layout();
690 std_layout(const std_layout &);
691 ~std_layout();
692 private:
693 int n;
695 int check_std_layout[__is_standard_layout(std_layout) ? 1 : -1];
697 struct aggregate {
698 int x;
699 int y;
700 trivial t;
701 std_layout sl;
703 aggregate aggr = {};
705 void f(...);
706 void g(trivial t) { f(t); }
707 #if __cplusplus < 201103L
708 // expected-error@-2 {{non-POD}}
709 #endif
711 void jump() {
712 goto x;
713 #if __cplusplus < 201103L
714 // expected-error@-2 {{cannot jump}}
715 // expected-note@+2 {{non-POD}}
716 #endif
717 trivial t;
718 x: ;
722 namespace dr569 { // dr569: yes c++11
723 // FIXME: This is a DR issue against C++98, so should probably apply there
724 // too.
725 ;;;;;
726 #if __cplusplus < 201103L
727 // expected-error@-2 {{C++11 extension}}
728 #endif
731 namespace dr570 { // dr570: dup 633
732 int n;
733 int &r = n; // expected-note {{previous}}
734 int &r = n; // expected-error {{redefinition}}
737 namespace dr571 { // dr571 unknown
738 // FIXME: Add a codegen test.
739 typedef int &ir;
740 int n;
741 const ir r = n; // expected-warning {{has no effect}} FIXME: Test if this has internal linkage.
744 namespace dr572 { // dr572: yes
745 enum E { a = 1, b = 2 };
746 int check[a + b == 3 ? 1 : -1];
749 namespace dr573 { // dr573: no
750 void *a;
751 int *b = reinterpret_cast<int*>(a);
752 void (*c)() = reinterpret_cast<void(*)()>(a);
753 void *d = reinterpret_cast<void*>(c);
754 #if __cplusplus < 201103L
755 // expected-error@-3 {{extension}}
756 // expected-error@-3 {{extension}}
757 #endif
758 void f() { delete a; } // expected-error {{cannot delete}}
759 int n = d - a; // expected-error {{arithmetic on pointers to void}}
760 // FIXME: This is ill-formed.
761 template<void*> struct S;
762 template<int*> struct T;
765 namespace dr574 { // dr574: yes
766 struct A {
767 A &operator=(const A&) const; // expected-note {{different qualifiers}}
769 struct B {
770 B &operator=(const B&) volatile; // expected-note {{different qualifiers}}
772 #if __cplusplus >= 201103L
773 struct C {
774 C &operator=(const C&) &; // #574-overload1 \
775 // expected-note {{not viable}} \
776 // expected-note {{here}}
779 struct D {
780 D &operator=(const D&) &&; // #574-overload2 \
781 // expected-note {{not viable}} \
782 // expected-note {{here}}
784 void test(C c, D d) {
785 c = c;
786 C() = c; // expected-error {{no viable}}
787 d = d; // expected-error {{no viable}}
788 D() = d;
790 #endif
791 struct Test {
792 friend A &A::operator=(const A&); // expected-error {{does not match}}
793 friend B &B::operator=(const B&); // expected-error {{does not match}}
794 #if __cplusplus >= 202302L
795 friend C &C::operator=(const C&); // expected-error {{conflicting types for 'operator='}}
796 friend D &D::operator=(const D&); // expected-error {{conflicting types for 'operator='}} __cplusplus >= 201103L
797 #elif __cplusplus >= 201103L
798 // FIXME: We shouldn't produce the 'cannot overload' diagnostics here.
799 friend C &C::operator=(const C&); // expected-error {{does not match}} \
800 // expected-error {{cannot overload}} \
801 // expected-note@#574-overload1 {{candidate}}
802 friend D &D::operator=(const D&); // expected-error {{does not match}} \
803 // expected-error {{cannot overload}} \
804 // expected-note@#574-overload2 {{candidate}}
805 #endif
809 namespace dr575 { // dr575: yes
810 template<typename T, typename U = typename T::type> void a(T); void a(...); // expected-error 0-1{{extension}}
811 template<typename T, typename T::type U = 0> void b(T); void b(...); // expected-error 0-1{{extension}}
812 template<typename T, int U = T::value> void c(T); void c(...); // expected-error 0-1{{extension}}
813 template<typename T> void d(T, int = T::value); void d(...); // expected-error {{cannot be used prior to '::'}}
814 void x() {
815 a(0);
816 b(0);
817 c(0);
818 d(0); // expected-note {{in instantiation of default function argument}}
821 template<typename T = int&> void f(T* = 0); // expected-error 0-1{{extension}}
822 template<typename T = int> void f(T = 0); // expected-error 0-1{{extension}}
823 void g() { f<>(); }
825 template<typename T> T &h(T *);
826 template<typename T> T *h(T *);
827 void *p = h((void*)0);
830 namespace dr576 { // dr576: yes
831 typedef void f() {} // expected-error {{function definition declared 'typedef'}}
832 void f(typedef int n); // expected-error {{invalid storage class}}
833 void f(char c) { typedef int n; }
836 namespace dr577 { // dr577: yes
837 typedef void V;
838 typedef const void CV;
839 void a(void);
840 void b(const void); // expected-error {{qualifiers}}
841 void c(V);
842 void d(CV); // expected-error {{qualifiers}}
843 void (*e)(void) = c;
844 void (*f)(const void); // expected-error {{qualifiers}}
845 void (*g)(V) = a;
846 void (*h)(CV); // expected-error {{qualifiers}}
847 template<typename T> void i(T); // expected-note 2{{requires 1 arg}}
848 template<typename T> void j(void (*)(T)); // expected-note 2{{argument may not have 'void' type}}
849 void k() {
850 a();
851 c();
852 i<void>(); // expected-error {{no match}}
853 i<const void>(); // expected-error {{no match}}
854 j<void>(0); // expected-error {{no match}}
855 j<const void>(0); // expected-error {{no match}}
859 namespace dr580 { // dr580: partial
860 class C;
861 struct A { static C c; };
862 struct B { static C c; };
863 class C {
864 C(); // expected-note {{here}}
865 ~C(); // expected-note {{here}}
867 typedef int I; // expected-note 2{{here}}
868 template<int> struct X;
869 template<int> friend struct Y;
870 template<int> void f();
871 template<int> friend void g();
872 friend struct A;
875 template<C::I> struct C::X {};
876 template<C::I> struct Y {};
877 template<C::I> struct Z {}; // expected-error {{private}}
879 struct C2 {
880 class X {
881 struct A;
882 typedef int I;
883 friend struct A;
885 class Y {
886 template<X::I> struct A {}; // FIXME: We incorrectly accept this
887 // because we think C2::Y::A<...> might
888 // instantiate to C2::X::A
892 template<C::I> void C::f() {}
893 template<C::I> void g() {}
894 template<C::I> void h() {} // expected-error {{private}}
896 C A::c;
897 C B::c; // expected-error 2{{private}}
900 // dr582: na
902 namespace dr583 { // dr583: 4
903 // see n3624
904 int *p;
905 bool b1 = p < 0; // expected-error {{ordered comparison between pointer and zero}}
906 bool b2 = p > 0; // expected-error {{ordered comparison between pointer and zero}}
907 bool b3 = p <= 0; // expected-error {{ordered comparison between pointer and zero}}
908 bool b4 = p >= 0; // expected-error {{ordered comparison between pointer and zero}}
911 // dr584: na
913 namespace dr585 { // dr585: yes
914 template<typename> struct T;
915 struct A {
916 friend T;
917 #if __cplusplus <= 201402L
918 // expected-error@-2 {{a type specifier is required}} expected-error@-2 {{can only be classes or functions}}
919 #else
920 // expected-error@-4 {{use of class template 'T' requires template arguments; argument deduction not allowed in friend declaration}}
921 // expected-note@-7 {{here}}
922 #endif
923 // FIXME: It's not clear whether the standard allows this or what it means,
924 // but the DR585 writeup suggests it as an alternative.
925 template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
927 template<template<typename> class T> struct B {
928 friend T;
929 #if __cplusplus <= 201402L
930 // expected-error@-2 {{a type specifier is required}} expected-error@-2 {{can only be classes or functions}}
931 #else
932 // expected-error@-4 {{use of template template parameter 'T' requires template arguments; argument deduction not allowed in friend declaration}}
933 // expected-note@-6 {{here}}
934 #endif
935 template<typename U> friend T<U>; // expected-error {{must use an elaborated type}}
939 // dr586: na
941 namespace dr587 { // dr587: yes
942 template<typename T> void f(bool b, const T x, T y) {
943 const T *p = &(b ? x : y);
945 struct S {};
946 template void f(bool, const int, int);
947 template void f(bool, const S, S);
950 namespace dr588 { // dr588: yes
951 struct A { int n; }; // expected-note {{ambiguous}}
952 template<typename T> int f() {
953 struct S : A, T { int f() { return n; } } s;
954 int a = s.f();
955 int b = s.n; // expected-error {{found in multiple}}
957 struct B { int n; }; // expected-note {{ambiguous}}
958 int k = f<B>(); // expected-note {{here}}
961 namespace dr589 { // dr589: yes
962 struct B { };
963 struct D : B { };
964 D f();
965 extern const B &b;
966 bool a;
967 const B *p = &(a ? f() : b); // expected-error {{temporary}}
968 const B *q = &(a ? D() : b); // expected-error {{temporary}}
971 namespace dr590 { // dr590: yes
972 template<typename T> struct A {
973 struct B {
974 struct C {
975 A<T>::B::C f(A<T>::B::C); // ok, no 'typename' required.
979 template<typename T> typename A<T>::B::C A<T>::B::C::f(A<T>::B::C) {}
982 namespace dr591 { // dr591: no
983 template<typename T> struct A {
984 typedef int M;
985 struct B {
986 typedef void M;
987 struct C;
991 template<typename T> struct A<T>::B::C : A<T> {
992 // FIXME: Should find member of non-dependent base class A<T>.
993 M m; // expected-error {{incomplete type 'M' (aka 'void'}}
997 // dr592: na
998 // dr593 needs an IRGen test.
999 // dr594: na
1001 namespace dr595 { // dr595: dup 1330
1002 template<class T> struct X {
1003 void f() throw(T) {}
1004 #if __cplusplus > 201402L
1005 // expected-error@-2 {{ISO C++17 does not allow}} expected-note@-2 {{use 'noexcept}}
1006 #endif
1008 struct S {
1009 X<S> xs;
1013 // dr597: na
1015 namespace dr598 { // dr598: yes
1016 namespace N {
1017 void f(int);
1018 void f(char);
1019 // Not found by ADL.
1020 void g(void (*)(int));
1021 void h(void (*)(int));
1023 namespace M {
1024 struct S {};
1025 int &h(void (*)(S));
1027 void i(M::S);
1028 void i();
1030 int &g(void(*)(char));
1031 int &r = g(N::f);
1032 int &s = h(N::f); // expected-error {{undeclared}}
1033 int &t = h(N::i);
1036 namespace dr599 { // dr599: partial
1037 typedef int Fn();
1038 struct S { operator void*(); };
1039 struct T { operator Fn*(); };
1040 struct U { operator int*(); operator void*(); }; // expected-note 2{{conversion}}
1041 struct V { operator int*(); operator Fn*(); };
1042 void f(void *p, void (*q)(), S s, T t, U u, V v) {
1043 delete p; // expected-error {{cannot delete}}
1044 delete q; // expected-error {{cannot delete}}
1045 delete s; // expected-error {{cannot delete}}
1046 delete t; // expected-error {{cannot delete}}
1047 // FIXME: This is valid, but is rejected due to a non-conforming GNU
1048 // extension allowing deletion of pointers to void.
1049 delete u; // expected-error {{ambiguous}}
1050 delete v;