Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr6xx.cpp
blobc5cd478c5e331948d36d88a279322c2edde5331b
1 // RUN: %clang_cc1 -std=c++98 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
2 // RUN: %clang_cc1 -std=c++11 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
3 // RUN: %clang_cc1 -std=c++14 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
4 // RUN: %clang_cc1 -std=c++17 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
5 // RUN: %clang_cc1 -std=c++20 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
6 // RUN: %clang_cc1 -std=c++23 %s -verify -fexceptions -fcxx-exceptions -pedantic-errors -fno-spell-checking
8 namespace dr600 { // dr600: yes
9 struct S {
10 void f(int);
12 private:
13 void f(double); // expected-note {{declared private here}}
16 void g(S *sp) {
17 sp->f(2);
18 // access control is applied after overload resolution
19 sp->f(2.2); // expected-error {{is a private member}}
21 } // namespace dr600
23 namespace std {
24 struct type_info {};
25 __extension__ typedef __SIZE_TYPE__ size_t;
26 } // namespace std
28 namespace dr601 { // dr601: yes
29 #if __cplusplus >= 201103L
30 #define MAX __LLONG_MAX__
31 #else
32 #define MAX __LONG_MAX__
33 #endif
35 #if 0x8000 < -1
36 #error 0x8000 should be signed
37 #endif
39 #if MAX > 0xFFFFFFFF && 0x80000000 < -1
40 #error 0x80000000 should be signed
41 #endif
43 #if __INT_MAX__ == 0x7FFFFFFF
44 _Static_assert(0x80000000 < -1, "0x80000000 should be unsigned"); // expected-error {{C11}}
45 #endif
47 #if MAX > 0xFFFFFFFFFFFFFFFF && 0x8000000000000000 < -1
48 #error 0x8000000000000000 should be signed
49 #endif
51 #if __cplusplus >= 201103L && __LLONG_MAX__ == 0x7FFFFFFFFFFFFFFF
52 static_assert(0x8000000000000000 < -1, "0x8000000000000000 should be unsigned"); // expected-error {{C11}}
53 #endif
55 #undef MAX
58 namespace dr602 { // dr602: yes
59 template<class T> struct A {
60 template<class U> friend struct A;
63 template<class T> struct B {
64 class C {
65 template<class U> friend struct B;
66 typedef int type;
68 typename C::type ct; // ok, befriended
70 B<int> b;
73 namespace dr603 { // dr603: yes
74 template<unsigned char> struct S {};
75 typedef S<'\001'> S1;
76 typedef S<(1ul << __CHAR_BIT__) + 1> S1;
77 #if __cplusplus >= 201103L
78 // expected-error@-2 {{cannot be narrowed}}
79 #endif
82 // dr604: na
83 // dr605 needs IRGen test
85 namespace dr606 { // dr606: yes
86 #if __cplusplus >= 201103L
87 template<typename T> struct S {};
88 template<typename T> void f(S<T> &&); // expected-note {{expects an rvalue}}
89 template<typename T> void g(T &&);
90 template<typename T> void h(const T &&); // expected-note {{expects an rvalue}}
92 void test(S<int> s) {
93 f(s); // expected-error {{no match}}
94 g(s);
95 h(s); // expected-error {{no match}}
97 g(test);
98 h(test); // ok, an rvalue reference can bind to a function lvalue
100 #endif
103 namespace dr607 { // dr607: yes
104 namespace example1 {
105 struct Y {};
107 template <typename T> struct X : public virtual Y {};
109 template <typename T> class A : public X<T> {
110 template <typename S> A(S) : S() {}
113 template A<int>::A(Y);
114 } // namespace example1
116 namespace example2 {
117 namespace N {
118 struct B {
119 B(int);
121 typedef B typedef_B;
122 struct D : B {
123 D();
125 } // namespace N
127 N::D::D() : typedef_B(0) {}
128 } // namespace example2
129 } // namespace dr607
131 namespace dr608 { // dr608: yes
132 struct A { virtual void f(); };
133 struct B : A {};
134 struct C : A { void f(); };
135 struct D : B, C {};
138 int dr610[-0u == 0u ? 1 : -1]; // dr610: yes
140 namespace dr611 { // dr611: yes
141 int k;
142 struct S { int &r; } s = { k ? k : k };
145 // dr612: na
147 namespace dr613 { // dr613: yes c++11
148 // see also n2253
149 struct A { int n; static void f(); };
150 int f(int);
151 struct B { virtual void f(); };
152 B &g(int);
154 int an1 = sizeof(A::n);
155 int an2 = sizeof(A::n + 1); // valid per dr850
156 int an3 = sizeof A::n;
157 int an4 = sizeof(f(A::n));
158 int an5 = sizeof(g(A::n));
159 const std::type_info &an6 = typeid(A::n);
160 const std::type_info &an7 = typeid(A::n + 1);
161 const std::type_info &an8 = typeid(f(A::n));
162 const std::type_info &an9 = typeid(g(A::n)); // expected-error {{non-static}}
163 #if __cplusplus < 201103L
164 // expected-error@-10 {{non-static}}
165 // expected-error@-10 {{non-static}}
166 // expected-error@-10 {{non-static}}
167 // expected-error@-10 {{non-static}}
168 // expected-error@-10 {{non-static}}
169 // expected-error@-10 {{non-static}}
170 // expected-error@-10 {{non-static}}
171 // expected-error@-10 {{non-static}}
172 #endif
174 void A::f() {
175 int an1 = sizeof n;
176 const std::type_info &an2 = typeid(n + 1);
177 #if __cplusplus < 201103L
178 // expected-error@-3 {{static}}
179 // expected-error@-3 {{static}}
180 #endif
181 const std::type_info &an3 = typeid(g(n)); // expected-error {{static}}
185 int dr614_a[(-1) / 2 == 0 ? 1 : -1]; // dr614: yes
186 int dr614_b[(-1) % 2 == -1 ? 1 : -1];
188 namespace dr615 { // dr615: yes
189 int f();
190 static int n = f();
193 namespace dr616 { // dr616: 4
194 #if __cplusplus >= 201103L
195 struct S { int n; } s;
196 S f();
197 using T = decltype((S().n));
198 using T = decltype((static_cast<S&&>(s).n));
199 using T = decltype((f().n));
200 using T = decltype(S().*&S::n);
201 using T = decltype(static_cast<S&&>(s).*&S::n);
202 using T = decltype(f().*&S::n);
203 using T = int&&;
205 using U = decltype(S().n);
206 using U = decltype(static_cast<S&&>(s).n);
207 using U = int;
208 #endif
211 namespace dr618 { // dr618: yes
212 #if (unsigned)-1 > 0
213 #error wrong
214 #endif
217 namespace dr619 { // dr619: yes
218 extern int x[10];
219 struct S { static int x[10]; };
221 int x[];
222 _Static_assert(sizeof(x) == sizeof(int) * 10, ""); // expected-error {{C11}}
223 extern int x[];
224 _Static_assert(sizeof(x) == sizeof(int) * 10, ""); // expected-error {{C11}}
226 int S::x[];
227 _Static_assert(sizeof(S::x) == sizeof(int) * 10, ""); // expected-error {{C11}}
229 void f() {
230 extern int x[];
231 sizeof(x); // expected-error {{incomplete}}
235 // dr620: dup 568
237 namespace dr621 { // dr621: yes
238 template<typename T> T f();
239 template<> int f() {} // expected-note {{previous}}
240 template<> int f<int>() {} // expected-error {{redefinition}}
243 // dr623: na
244 // FIXME: Add documentation saying we allow invalid pointer values.
246 // dr624 needs an IRGen check.
248 namespace dr625 { // dr625: yes
249 template<typename T> struct A {};
250 A<auto> x = A<int>(); // expected-error {{'auto' not allowed in template argument}} expected-error 0-1{{extension}}
251 void f(int);
252 void (*p)(auto) = f; // expected-error {{'auto' not allowed in function prototype}} expected-error 0-1{{extension}}
255 namespace dr626 { // dr626: yes
256 #define STR(x) #x
257 char c[2] = STR(c); // ok, type matches
258 wchar_t w[2] = STR(w); // expected-error {{initializing wide char array with non-wide string literal}}
261 namespace dr627 { // dr627: yes
262 void f() {
263 true a = 0; // expected-error +{{}} expected-warning {{unused}}
267 // dr628: na
269 namespace dr629 { // dr629: yes
270 typedef int T;
271 int n = 1;
272 void f() {
273 auto T = 2;
274 #if __cplusplus < 201103L
275 // expected-error@-2 {{expected unqualified-id}}
276 #else
277 // expected-note@-4 {{previous}}
278 #endif
280 auto T(n);
281 #if __cplusplus >= 201103L
282 // expected-error@-2 {{redefinition of 'T'}}
283 #endif
287 namespace dr630 { // dr630: yes
288 const bool MB_EQ_WC =
289 ' ' == L' ' && '\t' == L'\t' && '\v' == L'\v' && '\r' == L'\r' &&
290 '\n' == L'\n' && //
291 'a' == L'a' && 'b' == L'b' && 'c' == L'c' && 'd' == L'd' && 'e' == L'e' &&
292 'f' == L'f' && 'g' == L'g' && 'h' == L'h' && 'i' == L'i' && 'j' == L'j' &&
293 'k' == L'k' && 'l' == L'l' && 'm' == L'm' && 'n' == L'n' && 'o' == L'o' &&
294 'p' == L'p' && 'q' == L'q' && 'r' == L'r' && 's' == L's' && 't' == L't' &&
295 'u' == L'u' && 'v' == L'v' && 'w' == L'w' && 'x' == L'x' && 'y' == L'y' &&
296 'z' == L'z' && //
297 'A' == L'A' && 'B' == L'B' && 'C' == L'C' && 'D' == L'D' && 'E' == L'E' &&
298 'F' == L'F' && 'G' == L'G' && 'H' == L'H' && 'I' == L'I' && 'J' == L'J' &&
299 'K' == L'K' && 'L' == L'L' && 'M' == L'M' && 'N' == L'N' && 'O' == L'O' &&
300 'P' == L'P' && 'Q' == L'Q' && 'R' == L'R' && 'S' == L'S' && 'T' == L'T' &&
301 'U' == L'U' && 'V' == L'V' && 'W' == L'W' && 'X' == L'X' && 'Y' == L'Y' &&
302 'Z' == L'Z' && //
303 '0' == L'0' && '1' == L'1' && '2' == L'2' && '3' == L'3' && '4' == L'4' &&
304 '5' == L'5' && '6' == L'6' && '7' == L'7' && '8' == L'8' &&
305 '9' == L'9' && //
306 '_' == L'_' && '{' == L'{' && '}' == L'}' && '[' == L'[' && ']' == L']' &&
307 '#' == L'#' && '(' == L'(' && ')' == L')' && '<' == L'<' && '>' == L'>' &&
308 '%' == L'%' && ':' == L':' && ';' == L';' && '.' == L'.' && '?' == L'?' &&
309 '*' == L'*' && '+' == L'+' && '-' == L'-' && '/' == L'/' && '^' == L'^' &&
310 '&' == L'&' && '|' == L'|' && '~' == L'~' && '!' == L'!' && '=' == L'=' &&
311 ',' == L',' && '\\' == L'\\' && '"' == L'"' && '\'' == L'\'';
312 #if __STDC_MB_MIGHT_NEQ_WC__
313 #ifndef __FreeBSD__ // PR22208, FreeBSD expects us to give a bad (but conforming) answer here.
314 _Static_assert(!MB_EQ_WC, "__STDC_MB_MIGHT_NEQ_WC__ but all basic source characters have same representation"); // expected-error {{C11}}
315 #endif
316 #else
317 _Static_assert(MB_EQ_WC, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs"); // expected-error {{C11}}
318 #endif
321 // dr631: na
323 namespace dr632 { // dr632: yes
324 struct S { int n; } s = {{5}}; // expected-warning {{braces}}
327 // dr633: na
328 // see also n2993
330 namespace dr634 { // dr634: yes
331 struct S { S(); S(const S&); virtual void f(); ~S(); };
332 int f(...);
333 char f(int);
334 template<typename T> int (&g(T))[sizeof f(T())];
335 int (&a)[sizeof(int)] = g(S());
336 int (&b)[1] = g(0);
337 int k = f(S()); // expected-error {{cannot pass}}
340 namespace dr635 { // dr635: yes
341 template<typename T> struct A { A(); ~A(); };
342 template<typename T> A<T>::A<T>() {} // expected-error {{cannot have template arguments}}
343 template<typename T> A<T>::~A<T>() {}
345 template<typename T> struct B { B(); ~B(); };
346 template<typename T> B<T>::B() {}
347 template<typename T> B<T>::~B() {}
349 struct C { template<typename T> C(); C(); };
350 template<typename T> C::C() {}
351 C::C() {}
352 template<> C::C<int>() {} // expected-error {{constructor name}} expected-error {{unqualified-id}}
353 /*FIXME: needed for error recovery:*/;
355 template<typename T> struct D { template<typename U> D(); D(); };
356 template<typename T> D<T>::D() {} // expected-note {{previous}}
357 template<typename T> template<typename U> D<T>::D() {}
358 template<typename T> D<T>::D<T>() {} // expected-error {{redefinition}} expected-error {{cannot have template arg}}
361 namespace dr637 { // dr637: yes
362 void f(int i) {
363 i = ++i + 1;
364 i = i++ + 1;
365 #if __cplusplus < 201703L
366 // expected-warning@-2 {{unsequenced}}
367 #endif
371 namespace dr638 { // dr638: no
372 template<typename T> struct A {
373 struct B;
374 void f();
375 void g();
376 struct C {
377 void h();
381 class X {
382 typedef int type;
383 template<class T> friend struct A<T>::B; // expected-warning {{not supported}}
384 template<class T> friend void A<T>::f(); // expected-warning {{not supported}}
385 template<class T> friend void A<T>::g(); // expected-warning {{not supported}}
386 template<class T> friend void A<T>::C::h(); // expected-warning {{not supported}}
389 template<> struct A<int> {
390 X::type a; // FIXME: private
391 struct B {
392 X::type b; // ok
394 int f() { X::type c; } // FIXME: private
395 void g() { X::type d; } // ok
396 struct D {
397 void h() { X::type e; } // FIXME: private
402 namespace dr639 { // dr639: yes
403 void f(int i) {
404 void((i = 0) + (i = 0)); // expected-warning {{unsequenced}}
408 namespace dr641 { // dr641: yes
409 namespace std_example {
410 struct abc;
412 struct xyz {
413 xyz(); // expected-note 0-1{{candidate}}
414 xyz(xyz &); // expected-note 0-1{{candidate}}
416 operator xyz &() = delete; // expected-error 0-1{{extension}} expected-warning {{will never be used}}
417 operator abc &() = delete; // expected-error 0-1{{extension}}
420 struct abc : xyz {};
422 template<typename T>
423 void use(T &); // expected-note {{expects an lvalue}}
424 void test() {
425 use<xyz>(xyz()); // expected-error {{no match}}
426 use<const xyz>(xyz());
427 #if __cplusplus < 201103L
428 // expected-error-re@-2 {{no viable constructor copying parameter of type '{{.*}}xyz'}}
429 #endif
433 template<typename T> struct error { typedef typename T::error type; };
435 struct A {
436 template<typename T, typename error<T>::type = 0> operator T() const; // expected-error 0-1{{extension}}
438 A a;
439 void f(A&); // expected-note 2{{candidate}}
440 void g(const A ca) {
441 f(A()); // expected-error {{no match}}
442 f(ca); // expected-error {{no match}}
443 (void)A();
444 (void)ca;
448 namespace dr642 { // dr642: yes
449 void f() {
450 const int i = 2;
452 char i[i];
453 _Static_assert(sizeof(i) == 2, ""); // expected-error {{C11}}
457 struct s { int a; };
458 void g(int s) {
459 struct s *p = new struct s;
460 p->a = s;
464 #if __cplusplus >= 201103L
465 namespace dr643 { // dr643: yes
466 struct A {
467 int x;
468 auto f() -> decltype(this->x);
469 auto f(A &a) -> decltype(a.x);
470 auto g() -> decltype(x);
471 auto h() -> decltype(this->y); // expected-error {{no member named 'y'}}
472 auto h(A &a) -> decltype(a.y); // expected-error {{no member named 'y'}}
473 auto i() -> decltype(y); // expected-error {{undeclared identifier 'y'}}
474 int y;
477 #endif
479 #if __cplusplus >= 201103L
480 namespace dr644 { // dr644: partial
481 struct A {
482 A() = default;
483 int x, y;
485 static_assert(__is_literal_type(A), "");
487 struct B : A {};
488 static_assert(__is_literal_type(B), "");
490 struct C : virtual A {};
491 static_assert(!__is_literal_type(C), "");
493 struct D { C c; };
494 static_assert(!__is_literal_type(D), "");
496 // FIXME: According to DR644, E<C> is a literal type despite having virtual
497 // base classes. This appears to be a wording defect.
498 template<typename T>
499 struct E : T {
500 constexpr E() = default;
502 static_assert(!__is_literal_type(E<C>), "");
504 #endif
506 // dr645 increases permission to optimize; it's not clear that it's possible to
507 // test for this.
508 // dr645: na
510 #if __cplusplus >= 201103L
511 namespace dr646 { // dr646: sup 981
512 struct A {
513 constexpr A(const A&) = default; // ok
516 struct B {
517 constexpr B() {}
518 B(B&);
520 constexpr B b = {}; // ok
522 #endif
524 #if __cplusplus >= 201103L
525 namespace dr647 { // dr647: yes
526 // This is partially superseded by dr1358.
527 struct A {
528 constexpr virtual void f() const;
529 constexpr virtual void g() const {}
530 #if __cplusplus <= 201703L
531 // expected-error@-2 {{virtual function cannot be constexpr}}
532 #endif
535 struct X { virtual void f() const; };
536 #if __cplusplus <= 201703L
537 // expected-note@-2 {{overridden}}
538 #endif
539 struct B : X {
540 constexpr void f() const {}
541 #if __cplusplus <= 201703L
542 // expected-error@-2 {{virtual function cannot be constexpr}}
543 #endif
546 struct NonLiteral { NonLiteral() {} }; // expected-note {{not an aggregate and has no constexpr constructors}}
548 struct C {
549 constexpr C(NonLiteral);
550 constexpr C(NonLiteral, int) {} // expected-error {{not a literal type}}
551 constexpr C() try {} catch (...) {}
552 #if __cplusplus <= 201703L
553 // expected-error@-2 {{function try block in constexpr constructor is a C++20 extension}}
554 #endif
555 #if __cplusplus < 201402L
556 // expected-error@-5 {{use of this statement in a constexpr constructor is a C++14 extension}}
557 #endif
560 struct D {
561 operator int() const;
562 constexpr D(int) {}
563 D(float); // expected-note 2{{declared here}}
565 constexpr int get();
566 struct E {
567 int n;
568 D d;
570 // FIXME: We should diagnose this, as the conversion function is not
571 // constexpr. However, that part of this issue is supreseded by dr1364 and
572 // others; no diagnostic is required for this any more.
573 constexpr E()
574 : n(D(0)),
575 d(0) {}
577 constexpr E(int) // expected-error {{never produces a constant expression}}
578 : n(0),
579 d(0.0f) {} // expected-note {{non-constexpr constructor}}
580 constexpr E(float f) // expected-error {{never produces a constant expression}}
581 : n(get()),
582 d(D(0) + f) {} // expected-note {{non-constexpr constructor}}
585 #endif
587 #if __cplusplus >= 201103L
588 namespace dr648 { // dr648: yes
589 int f();
590 constexpr int a = (true ? 1 : f());
591 constexpr int b = false && f();
592 constexpr int c = true || f();
594 #endif
596 #if __cplusplus >= 201103L
597 namespace dr649 { // dr649: yes
598 alignas(0x200000000) int n; // expected-error {{requested alignment}}1
599 struct alignas(0x200000000) X {}; // expected-error {{requested alignment}}
600 struct Y {
601 int n alignas(0x200000000); // expected-error {{requested alignment}}
603 struct alignas(256) Z {};
604 // This part is superseded by dr2130 and eventually by aligned allocation support.
605 auto *p = new Z;
607 #endif
609 // dr650 FIXME: add codegen test
611 #if __cplusplus >= 201103L
612 namespace dr651 { // dr651: yes
613 struct X {
614 virtual X &f();
616 struct Y : X {
617 Y &f();
619 using T = decltype(((X&&)Y()).f());
620 using T = X &;
622 #endif
624 #if __cplusplus >= 201103L
625 namespace dr652 { // dr652: yes
626 constexpr int n = 1.2 * 3.4;
627 static_assert(n == 4, "");
629 #endif
631 // dr653 FIXME: add codegen test
633 #if __cplusplus >= 201103L
634 namespace dr654 { // dr654: sup 1423
635 void f() {
636 if (nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}}
637 bool b = nullptr; // expected-error {{cannot initialize a variable of type 'bool' with an rvalue of type 'std::nullptr_t'}}
638 if (nullptr == 0) {}
639 if (nullptr != 0) {}
640 if (nullptr <= 0) {} // expected-error {{invalid operands}}
641 if (nullptr == 1) {} // expected-error {{invalid operands}}
642 if (!nullptr) {} // expected-warning {{implicit conversion of nullptr constant to 'bool'}}
643 decltype(nullptr) n = 0;
644 static_cast<int>(nullptr); // expected-error {{not allowed}}
645 (void)static_cast<decltype(nullptr)>(0);
646 static_cast<decltype(nullptr)>(1); // expected-error {{not allowed}}
647 void(true ? nullptr : 0);
648 void(true ? 0 : nullptr);
651 #endif
653 namespace dr655 { // dr655: yes
654 struct A { A(int); }; // expected-note 2-3{{not viable}}
655 // expected-note@-1 {{'dr655::A' declared here}}
656 struct B : A {
657 A a; // expected-note {{member is declared here}}
658 B();
659 B(int) : B() {} // expected-error 0-1 {{C++11}}
660 B(int*) : A() {} // expected-error {{no matching constructor}}
661 // expected-error@-1 {{must explicitly initialize the member 'a'}}
665 namespace dr656 { // dr656: yes
666 struct A { A(const A&) = delete; }; // expected-error 0-1 {{C++11}}
667 struct B : A {};
668 struct X { operator B(); } x;
669 const A &r = x;
670 struct Y : private A { // expected-note 2{{here}} expected-note 2{{candidate}}
671 operator B() volatile;
673 extern Y y;
674 extern volatile Y vy;
675 // Conversion not considered due to reference-related types.
676 const A &s = y; // expected-error {{private base class}}
677 const A &t = vy; // expected-error {{drops 'volatile'}}
679 struct C { operator struct D(); } c;
680 struct D : C {};
681 const D &d = c; // ok, D not reference-related to C
683 template<typename T> void accept(T); // expected-note {{candidate}}
684 template<typename T> void accept(...) = delete; // expected-error 0-1 {{C++11}} expected-note {{candidate}}
685 void f() {
686 accept<const A&>(x);
687 accept<const A&>(y); // expected-error {{private base class}}
688 accept<const A&>(vy); // expected-error {{call to deleted}} expected-error {{no matching constructor}}
689 accept<const D&>(c);
693 namespace dr657 { // dr657: partial
694 struct Abs { virtual void x() = 0; }; // expected-note {{unimplemented pure virtual method 'x' in 'Abs'}}
695 struct Der : public Abs { virtual void x(); };
697 struct Cnvt { template<typename F> Cnvt(F); };
699 void foo(Cnvt a);
700 void foo(Abs &a);
701 void f(Abs *a) { foo(*a); }
703 void bar(Abs &a);
704 template<typename T> void bar(T);
705 void g(Abs *a) { bar(*a); }
707 // FIXME: The following examples demonstrate that we might be accepting the
708 // above cases for the wrong reason.
710 struct C { C(Abs) {} }; // expected-error {{parameter type 'Abs' is an abstract class}}
711 struct Q { operator Abs() { __builtin_unreachable(); } } q; // expected-error {{return type 'Abs' is an abstract class}}
712 #if __cplusplus >= 201703L
713 // FIXME: We should *definitely* reject this.
714 C c = Q().operator Abs();
715 #endif
717 template<typename F> struct Cnvt2 { Cnvt2(F); typedef int type; };
719 // FIXME: We should reject this.
720 void baz(Abs &a);
721 template<typename T> typename Cnvt2<T>::type baz(T);
722 void h(Abs *a) { baz(*a); }
724 // FIXME: We should reject this too.
725 Cnvt2<Abs>::type err;
728 // dr658 FIXME: add codegen test
730 #if __cplusplus >= 201103L
731 namespace dr659 { // dr659: yes
732 static_assert(alignof(char) == alignof(char&), "");
733 static_assert(alignof(int) == alignof(int&), "");
734 int n = alignof(int(&)()); // expected-error {{application of 'alignof' to a function type}}
735 struct A; // expected-note {{forward}}
736 int m = alignof(A&); // expected-error {{application of 'alignof' to an incomplete type}}
738 #endif
740 #if __cplusplus >= 201103L
741 namespace dr660 { // dr660: yes
742 enum : int { a };
743 enum class { b }; // expected-error {{requires a name}}
744 auto x = a;
746 struct X {
747 enum : int { a };
748 enum class { b }; // expected-error {{requires a name}}
750 auto y = X::a;
752 #endif
754 // dr661 FIXME: add codegen test
756 namespace dr662 { // dr662: yes
757 template <typename T> void f(T t) {
758 T &tr = t;
759 T *tp = &t; // expected-error {{pointer to a reference}}
760 #if __cplusplus >= 201103L
761 auto *ap = &t;
762 #endif
764 void g(int n) { f<int&>(n); } // expected-note {{instantiation of}}
767 namespace dr663 { // dr663: sup P1949
768 int ЍЎ = 123;
771 #if __cplusplus >= 201103L
772 namespace dr664 { // dr664: yes
773 struct A { A(const A&) = delete; };
774 A &&f(A &&a, int n) {
775 if (n)
776 return f(static_cast<A&&>(a), n - 1);
777 return static_cast<A&&>(a);
780 #endif
782 namespace dr665 { // dr665: yes
783 struct A { virtual ~A(); };
784 struct B : A {} *b;
785 struct C : private A {} *c; // expected-note {{here}}
786 struct D : B, C {} *d;
788 struct VB : virtual A {} *vb;
789 struct VC : private virtual A {} *vc; // expected-note {{here}}
790 struct VD : VB, VC {} *vd;
792 void f() {
793 (void)dynamic_cast<A*>(b);
794 (void)dynamic_cast<A*>(c); // expected-error {{private}}
795 (void)dynamic_cast<A*>(d); // expected-error {{ambiguous}}
796 (void)dynamic_cast<A*>(vb);
797 (void)dynamic_cast<A*>(vc); // expected-error {{private}}, even though it could be valid at runtime
798 (void)dynamic_cast<A*>(vd);
802 namespace dr666 { // dr666: yes
803 struct P { friend P operator*(P, P); P(int); } p(0);
805 template<int> int f();
806 template<typename T> int f() {
807 T::type *p = 0; // expected-error {{missing 'typename'}}
808 int a(T::type); // expected-error {{missing 'typename'}}
809 return f<T::type>(); // expected-error {{missing 'typename'}}
811 struct X { static const int type = 0; };
812 struct Y { typedef int type; };
813 int a = f<X>();
814 int b = f<Y>(); // expected-note {{instantiation of}}
817 // Triviality is entirely different in C++98.
818 #if __cplusplus >= 201103L
819 namespace dr667 { // dr667: yes
820 struct A {
821 A() = default; // expected-warning {{explicitly defaulted default constructor is implicitly deleted}} expected-note{{replace 'default'}}
822 int &r; // expected-note {{because field 'r' of reference type 'int &' would not be initialized}}
824 static_assert(!__is_trivially_constructible(A), "");
826 struct B { ~B() = delete; };
827 union C { B b; };
828 static_assert(!__is_trivially_destructible(C), "");
830 struct D { D(const D&) = delete; };
831 struct E : D {};
832 static_assert(!__is_trivially_constructible(E, const E&), "");
834 struct F { F &operator=(F&&) = delete; };
835 struct G : F {};
836 static_assert(!__is_trivially_assignable(G, G&&), "");
838 #endif
840 // dr668 FIXME: add codegen test
842 #if __cplusplus >= 201103L
843 namespace dr669 { // dr669: yes
844 void f() {
845 int n;
846 using T = decltype(n);
847 using T = int;
848 using U = decltype((n));
849 using U = int &;
851 [=] {
852 using V = decltype(n);
853 using V = int;
854 using W = decltype((n));
855 using W = const int&;
856 } ();
858 struct X {
859 int n;
860 void f() const {
861 using X = decltype(n);
862 using X = int;
863 using Y = decltype((n));
864 using Y = const int&;
869 #endif
871 namespace dr671 { // dr671: yes
872 enum class E { e }; // expected-error 0-1 {{C++11}}
873 E e = static_cast<E>(0);
874 int n = static_cast<int>(E::e); // expected-error 0-1 {{C++11}}
875 int m = static_cast<int>(e); // expected-error 0-1 {{C++11}}
878 // dr672 FIXME: add codegen test
880 namespace dr673 { // dr673: yes
881 template<typename> struct X { static const int n = 0; };
883 class A {
884 friend class B *f();
885 class C *f();
886 void f(class D *);
887 enum { e = X<struct E>::n };
888 void g() { extern struct F *p; }
890 B *b;
891 C *c;
892 D *d;
893 E *e;
894 F *f; // expected-error {{unknown type name}}
897 namespace dr674 { // dr674: 8
898 template<typename T> int f(T);
900 int g(int);
901 template<typename T> int g(T);
903 int h(int);
904 template<typename T> int h(T);
906 class X {
907 friend int dr674::f(int);
908 friend int dr674::g(int);
909 friend int dr674::h<>(int);
910 int n; // expected-note 2{{private}}
913 template<typename T> int f(T) { return X().n; }
914 int g(int) { return X().n; }
915 template<typename T> int g(T) { return X().n; } // expected-error {{private}}
916 int h(int) { return X().n; } // expected-error {{private}}
917 template<typename T> int h(T) { return X().n; }
919 template int f(int);
920 template int g(int); // expected-note {{in instantiation of}}
921 template int h(int);
924 struct Y {
925 template<typename T> int f(T);
927 int g(int);
928 template<typename T> int g(T);
930 int h(int);
931 template<typename T> int h(T);
934 class Z {
935 friend int Y::f(int);
936 friend int Y::g(int);
937 friend int Y::h<>(int);
938 int n; // expected-note 2{{private}}
941 template<typename T> int Y::f(T) { return Z().n; }
942 int Y::g(int) { return Z().n; }
943 template<typename T> int Y::g(T) { return Z().n; } // expected-error {{private}}
944 int Y::h(int) { return Z().n; } // expected-error {{private}}
945 template<typename T> int Y::h(T) { return Z().n; }
947 // FIXME: Should the <> be required here?
948 template int Y::f<>(int);
949 template int Y::g<>(int); // expected-note {{in instantiation of}}
950 template int Y::h<>(int);
953 namespace dr675 { // dr675: dup 739
954 template<typename T> struct A { T n : 1; };
955 #if __cplusplus >= 201103L
956 static_assert(A<char>{1}.n < 0, ""); // expected-warning {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
957 static_assert(A<int>{1}.n < 0, ""); // expected-warning {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
958 static_assert(A<long long>{1}.n < 0, ""); // expected-warning {{implicit truncation from 'int' to a one-bit wide bit-field changes value from 1 to -1}}
959 #endif
962 // dr676: na
964 namespace dr677 { // dr677: no
965 struct A {
966 void *operator new(std::size_t);
967 void operator delete(void*) = delete; // expected-error 0-1{{C++11}} expected-note {{deleted}}
969 struct B {
970 void *operator new(std::size_t);
971 void operator delete(void*) = delete; // expected-error 0-1{{C++11}} expected-note 2{{deleted}}
972 virtual ~B();
974 void f(A *p) { delete p; } // expected-error {{deleted}}
975 // FIXME: This appears to be valid; we shouldn't even be looking up the 'operator delete' here.
976 void f(B *p) { delete p; } // expected-error {{deleted}}
977 B::~B() {} // expected-error {{deleted}}
980 // dr678 FIXME: check that the modules ODR check catches this
982 namespace dr679 { // dr679: yes
983 struct X {};
984 template<int> void operator+(X, X);
985 template<> void operator+<0>(X, X) {} // expected-note {{previous}}
986 template<> void operator+<0>(X, X) {} // expected-error {{redefinition}}
989 // dr680: na
991 #if __cplusplus >= 201103L
992 namespace dr681 { // dr681: partial
993 auto *a() -> int; // expected-error {{must specify return type 'auto', not 'auto *'}}
994 auto (*b)() -> int;
995 // FIXME: The errors here aren't great.
996 auto (*c()) -> int; // expected-error {{expected function body}}
997 auto ((*d)()) -> int; // expected-error {{expected ';'}} expected-error {{requires an initializer}}
999 // FIXME: This is definitely wrong. This should be
1000 // "function of () returning pointer to function of () returning int"
1001 // not a function with a deduced return type.
1002 auto (*e())() -> int; // expected-error 0-1{{C++14}}
1004 auto f() -> int (*)();
1005 auto g() -> auto (*)() -> int;
1007 #endif
1009 #if __cplusplus >= 201103L
1010 namespace dr683 { // dr683: yes
1011 struct A {
1012 A() = default;
1013 A(const A&) = default;
1014 A(A&);
1016 static_assert(__is_trivially_constructible(A, const A&), "");
1017 static_assert(!__is_trivially_constructible(A, A&), "");
1018 static_assert(!__is_trivial(A), "");
1020 struct B : A {};
1021 static_assert(__is_trivially_constructible(B, const B&), "");
1022 static_assert(__is_trivially_constructible(B, B&), "");
1023 static_assert(__is_trivial(B), "");
1025 #endif
1027 #if __cplusplus >= 201103L
1028 namespace dr684 { // dr684: sup 1454
1029 void f() {
1030 int a; // expected-note {{here}}
1031 constexpr int *p = &a; // expected-error {{constant expression}} expected-note {{pointer to 'a'}}
1034 #endif
1036 namespace dr685 { // dr685: yes
1037 enum E : long { e };
1038 #if __cplusplus < 201103L
1039 // expected-error@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
1040 #endif
1041 void f(int);
1042 int f(long);
1043 int a = f(e);
1045 enum G : short { g };
1046 #if __cplusplus < 201103L
1047 // expected-error@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
1048 #endif
1049 int h(short);
1050 void h(long);
1051 int b = h(g);
1053 int i(int);
1054 void i(long);
1055 int c = i(g);
1057 int j(unsigned int); // expected-note {{candidate}}
1058 void j(long); // expected-note {{candidate}}
1059 int d = j(g); // expected-error {{ambiguous}}
1061 // Valid per dr1601
1062 int k(short);
1063 void k(int);
1064 int x = k(g);
1067 namespace dr686 { // dr686: yes
1068 void f() {
1069 (void)dynamic_cast<struct A*>(0); // expected-error {{incomplete}} expected-note {{forward}}
1070 (void)dynamic_cast<struct A{}*>(0); // expected-error {{cannot be defined in a type specifier}}
1071 (void)typeid(struct B*);
1072 (void)typeid(struct B{}*); // expected-error {{cannot be defined in a type specifier}}
1073 (void)static_cast<struct C*>(0);
1074 (void)static_cast<struct C{}*>(0); // expected-error {{cannot be defined in a type specifier}}
1075 (void)reinterpret_cast<struct D*>(0);
1076 (void)reinterpret_cast<struct D{}*>(0); // expected-error {{cannot be defined in a type specifier}}
1077 (void)const_cast<struct E*>(0); // expected-error {{not allowed}}
1078 (void)const_cast<struct E{}*>(0); // expected-error {{cannot be defined in a type specifier}}
1079 (void)sizeof(struct F*);
1080 (void)sizeof(struct F{}*); // expected-error {{cannot be defined in a type specifier}}
1081 (void)new struct G*; // expected-note {{forward}}
1082 (void)new struct G{}*; // expected-error {{incomplete}}
1083 #if __cplusplus >= 201103L
1084 // expected-error@-2 {{expected expression}}
1085 (void)alignof(struct H*);
1086 (void)alignof(struct H{}*); // expected-error {{cannot be defined in a type specifier}}
1087 #endif
1088 (void)(struct I*)0;
1089 (void)(struct I{}*)0; // expected-error {{cannot be defined in a type specifier}}
1090 if (struct J *p = 0) {}
1091 if (struct J {} *p = 0) {} // expected-error {{cannot be defined in a condition}}
1092 for (struct K *p = 0; struct L *q = 0; ) {}
1093 for (struct K {} *p = 0; struct L {} *q = 0; ) {} // expected-error {{'L' cannot be defined in a condition}}
1094 #if __cplusplus >= 201103L
1095 using M = struct {};
1096 #endif
1097 struct N {
1098 operator struct O{}(){}; // expected-error {{cannot be defined in a type specifier}}
1100 try {}
1101 catch (struct P *) {} // expected-error {{incomplete}} expected-note {{forward}}
1102 catch (struct P {} *) {} // expected-error {{cannot be defined in a type specifier}}
1103 #if __cplusplus < 201703L
1104 void g() throw(struct Q); // expected-error {{incomplete}} expected-note {{forward}}
1105 void h() throw(struct Q {}); // expected-error {{cannot be defined in a type specifier}}
1106 #endif
1108 template<struct R *> struct X;
1109 template<struct R {} *> struct Y; // expected-error {{cannot be defined in a type specifier}}
1112 namespace dr687 { // dr687 (9 c++20, but the issue is still considered open)
1113 template<typename T> void f(T a) {
1114 // This is valid in C++20.
1115 g<int>(a);
1116 #if __cplusplus <= 201703L
1117 // expected-error@-2 {{C++20 extension}}
1118 #endif
1120 // This is not.
1121 template g<int>(a); // expected-error {{expected expression}}
1125 namespace dr692 { // dr692: 16
1126 // Also see dr1395.
1128 namespace temp_func_order_example2 {
1129 template <typename... T> struct A1 {}; // expected-error 0-1{{C++11}}
1130 template <typename U, typename... T> struct A2 {}; // expected-error 0-1{{C++11}}
1131 template <typename T1, typename... U> void e1(A1<T1, U...>) = delete; // expected-error 0-2{{C++11}}
1132 template <typename T1> void e1(A1<T1>);
1133 template <typename T1, typename... U> void e2(A2<T1, U...>) = delete; // expected-error 0-2{{C++11}}
1134 template <typename T1> void e2(A2<T1>);
1135 template <typename T, typename U> void f(U, A1<U, T> *p = 0) = delete; // expected-note {{candidate}} expected-error 0-1{{C++11}}
1136 template <typename U> int &f(U, A1<U, U> *p = 0); // expected-note {{candidate}}
1137 template <typename T> void g(T, T = T()); // expected-note {{candidate}}
1138 template <typename T, typename... U> void g(T, U...); // expected-note {{candidate}} expected-error 0-1{{C++11}}
1139 void h() {
1140 A1<int, int> a;
1141 int &r = f<int>(42, &a);
1142 A1<int> b1;
1143 e1(b1);
1144 A2<int> b2;
1145 e2(b2);
1146 f<int>(42); // expected-error {{ambiguous}}
1147 g(42); // expected-error {{ambiguous}}
1151 namespace temp_func_order_example3 {
1152 template <typename T, typename... U> void f(T, U...); // expected-error 0-1{{C++11}}
1153 template <typename T> void f(T);
1154 template <typename T, typename... U> int &g(T *, U...); // expected-error 0-1{{C++11}}
1155 template <typename T> void g(T);
1156 void h(int i) {
1157 // This is made ambiguous by dr692, but made valid again by dr1395.
1158 f(&i);
1159 int &r = g(&i);
1163 namespace temp_deduct_partial_example {
1164 template <typename... Args> char &f(Args... args); // expected-error 0-1{{C++11}}
1165 template <typename T1, typename... Args> short &f(T1 a1, Args... args); // expected-error 0-1{{C++11}}
1166 template <typename T1, typename T2> int &f(T1 a1, T2 a2);
1167 void g() {
1168 char &a = f();
1169 short &b = f(1, 2, 3);
1170 int &c = f(1, 2);
1174 namespace temp_deduct_type_example1 {
1175 template <class T1, class ...Z> class S; // expected-error 0-1{{C++11}}
1176 template <class T1, class ...Z> class S<T1, const Z&...>; // expected-error 0-1{{C++11}}
1177 template <class T1, class T2> class S<T1, const T2&> {};
1178 S<int, const int&> s;
1180 template<class T, class... U> struct A; // expected-error 0-1{{C++11}}
1181 template<class T1, class T2, class... U> struct A<T1,T2*,U...> {}; // expected-error 0-1{{C++11}}
1182 template<class T1, class T2> struct A<T1,T2>;
1183 template struct A<int, int*>;
1186 namespace temp_deduct_type_example3 {
1187 template<class T, class... U> void f(T*, U...){} // expected-error 0-1{{C++11}}
1188 template<class T> void f(T){}
1189 template void f(int*);
1193 namespace dr696 { // dr696: yes
1194 void f(const int*);
1195 void g() {
1196 const int N = 10; // expected-note 1+{{here}}
1197 struct A {
1198 void h() {
1199 int arr[N]; (void)arr;
1200 f(&N); // expected-error {{declared in enclosing}}
1203 #if __cplusplus >= 201103L
1204 (void) [] { int arr[N]; (void)arr; };
1205 (void)[] { f(&N); }; // expected-error {{cannot be implicitly captured}} expected-note {{here}} expected-note 2 {{capture 'N' by}} expected-note 2 {{default capture by}}
1206 #endif