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
13 void f(double); // expected-note {{declared private here}}
18 // access control is applied after overload resolution
19 sp
->f(2.2); // expected-error {{is a private member}}
25 __extension__
typedef __SIZE_TYPE__
size_t;
28 namespace dr601
{ // dr601: yes
29 #if __cplusplus >= 201103L
30 #define MAX __LLONG_MAX__
32 #define MAX __LONG_MAX__
36 #error 0x8000 should be signed
39 #if MAX > 0xFFFFFFFF && 0x80000000 < -1
40 #error 0x80000000 should be signed
43 #if __INT_MAX__ == 0x7FFFFFFF
44 _Static_assert(0x80000000 < -1, "0x80000000 should be unsigned"); // expected-error {{C11}}
47 #if MAX > 0xFFFFFFFFFFFFFFFF && 0x8000000000000000 < -1
48 #error 0x8000000000000000 should be signed
51 #if __cplusplus >= 201103L && __LLONG_MAX__ == 0x7FFFFFFFFFFFFFFF
52 static_assert(0x8000000000000000 < -1, "0x8000000000000000 should be unsigned"); // expected-error {{C11}}
58 namespace dr602
{ // dr602: yes
59 template<class T
> struct A
{
60 template<class U
> friend struct A
;
63 template<class T
> struct B
{
65 template<class U
> friend struct B
;
68 typename
C::type ct
; // ok, befriended
73 namespace dr603
{ // dr603: yes
74 template<unsigned char> struct S
{};
76 typedef S
<(1ul << __CHAR_BIT__
) + 1> S1
;
77 #if __cplusplus >= 201103L
78 // expected-error@-2 {{cannot be narrowed}}
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}}
93 f(s
); // expected-error {{no match}}
95 h(s
); // expected-error {{no match}}
98 h(test
); // ok, an rvalue reference can bind to a function lvalue
103 namespace dr607
{ // dr607: yes
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
127 N::D::D() : typedef_B(0) {}
128 } // namespace example2
131 namespace dr608
{ // dr608: yes
132 struct A
{ virtual void f(); };
134 struct C
: A
{ void f(); };
138 int dr610
[-0u == 0u ? 1 : -1]; // dr610: yes
140 namespace dr611
{ // dr611: yes
142 struct S
{ int &r
; } s
= { k
? k
: k
};
147 namespace dr613
{ // dr613: yes c++11
149 struct A
{ int n
; static void f(); };
151 struct B
{ virtual void f(); };
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}}
176 const std::type_info
&an2
= typeid(n
+ 1);
177 #if __cplusplus < 201103L
178 // expected-error@-3 {{static}}
179 // expected-error@-3 {{static}}
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
193 namespace dr616
{ // dr616: 4
194 #if __cplusplus >= 201103L
195 struct S
{ int n
; } s
;
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
);
205 using U
= decltype(S().n
);
206 using U
= decltype(static_cast<S
&&>(s
).n
);
211 namespace dr618
{ // dr618: yes
217 namespace dr619
{ // dr619: yes
219 struct S
{ static int x
[10]; };
222 _Static_assert(sizeof(x
) == sizeof(int) * 10, ""); // expected-error {{C11}}
224 _Static_assert(sizeof(x
) == sizeof(int) * 10, ""); // expected-error {{C11}}
227 _Static_assert(sizeof(S::x
) == sizeof(int) * 10, ""); // expected-error {{C11}}
231 sizeof(x
); // expected-error {{incomplete}}
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}}
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}}
252 void (*p
)(auto) = f
; // expected-error {{'auto' not allowed in function prototype}} expected-error 0-1{{extension}}
255 namespace dr626
{ // dr626: yes
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
263 true a
= 0; // expected-error +{{}} expected-warning {{unused}}
269 namespace dr629
{ // dr629: yes
274 #if __cplusplus < 201103L
275 // expected-error@-2 {{expected unqualified-id}}
277 // expected-note@-4 {{previous}}
281 #if __cplusplus >= 201103L
282 // expected-error@-2 {{redefinition of 'T'}}
287 namespace dr630
{ // dr630: yes
288 const bool MB_EQ_WC
=
289 ' ' == L
' ' && '\t' == L
'\t' && '\v' == L
'\v' && '\r' == L
'\r' &&
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' &&
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' &&
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' &&
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}}
317 _Static_assert(MB_EQ_WC
, "!__STDC_MB_MIGHT_NEQ_WC__ but some character differs"); // expected-error {{C11}}
323 namespace dr632
{ // dr632: yes
324 struct S
{ int n
; } s
= {{5}}; // expected-warning {{braces}}
330 namespace dr634
{ // dr634: yes
331 struct S
{ S(); S(const S
&); virtual void f(); ~S(); };
334 template<typename T
> int (&g(T
))[sizeof f(T())];
335 int (&a
)[sizeof(int)] = g(S());
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() {}
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
365 #if __cplusplus < 201703L
366 // expected-warning@-2 {{unsequenced}}
371 namespace dr638
{ // dr638: no
372 template<typename T
> struct A
{
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
394 int f() { X::type c
; } // FIXME: private
395 void g() { X::type d
; } // ok
397 void h() { X::type e
; } // FIXME: private
402 namespace dr639
{ // dr639: yes
404 void((i
= 0) + (i
= 0)); // expected-warning {{unsequenced}}
408 namespace dr641
{ // dr641: yes
409 namespace std_example
{
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}}
423 void use(T
&); // expected-note {{expects an lvalue}}
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'}}
433 template<typename T
> struct error
{ typedef typename
T::error type
; };
436 template<typename T
, typename error
<T
>::type
= 0> operator T() const; // expected-error 0-1{{extension}}
439 void f(A
&); // expected-note 2{{candidate}}
441 f(A()); // expected-error {{no match}}
442 f(ca
); // expected-error {{no match}}
448 namespace dr642
{ // dr642: yes
453 _Static_assert(sizeof(i
) == 2, ""); // expected-error {{C11}}
459 struct s
*p
= new struct s
;
464 #if __cplusplus >= 201103L
465 namespace dr643
{ // dr643: yes
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'}}
479 #if __cplusplus >= 201103L
480 namespace dr644
{ // dr644: partial
485 static_assert(__is_literal_type(A
), "");
488 static_assert(__is_literal_type(B
), "");
490 struct C
: virtual A
{};
491 static_assert(!__is_literal_type(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.
500 constexpr E() = default;
502 static_assert(!__is_literal_type(E
<C
>), "");
506 // dr645 increases permission to optimize; it's not clear that it's possible to
510 #if __cplusplus >= 201103L
511 namespace dr646
{ // dr646: sup 981
513 constexpr A(const A
&) = default; // ok
520 constexpr B b
= {}; // ok
524 #if __cplusplus >= 201103L
525 namespace dr647
{ // dr647: yes
526 // This is partially superseded by dr1358.
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}}
535 struct X
{ virtual void f() const; };
536 #if __cplusplus <= 201703L
537 // expected-note@-2 {{overridden}}
540 constexpr void f() const {}
541 #if __cplusplus <= 201703L
542 // expected-error@-2 {{virtual function cannot be constexpr}}
546 struct NonLiteral
{ NonLiteral() {} }; // expected-note {{not an aggregate and has no constexpr constructors}}
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}}
555 #if __cplusplus < 201402L
556 // expected-error@-5 {{use of this statement in a constexpr constructor is a C++14 extension}}
561 operator int() const;
563 D(float); // expected-note 2{{declared here}}
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.
577 constexpr E(int) // expected-error {{never produces a constant expression}}
579 d(0.0f
) {} // expected-note {{non-constexpr constructor}}
580 constexpr E(float f
) // expected-error {{never produces a constant expression}}
582 d(D(0) + f
) {} // expected-note {{non-constexpr constructor}}
587 #if __cplusplus >= 201103L
588 namespace dr648
{ // dr648: yes
590 constexpr int a
= (true ? 1 : f());
591 constexpr int b
= false && f();
592 constexpr int c
= true || f();
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}}
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.
609 // dr650 FIXME: add codegen test
611 #if __cplusplus >= 201103L
612 namespace dr651
{ // dr651: yes
619 using T
= decltype(((X
&&)Y()).f());
624 #if __cplusplus >= 201103L
625 namespace dr652
{ // dr652: yes
626 constexpr int n
= 1.2 * 3.4;
627 static_assert(n
== 4, "");
631 // dr653 FIXME: add codegen test
633 #if __cplusplus >= 201103L
634 namespace dr654
{ // dr654: sup 1423
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'}}
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);
653 namespace dr655
{ // dr655: yes
654 struct A
{ A(int); }; // expected-note 2-3{{not viable}}
655 // expected-note@-1 {{'dr655::A' declared here}}
657 A a
; // expected-note {{member is declared here}}
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}}
668 struct X
{ operator B(); } x
;
670 struct Y
: private A
{ // expected-note 2{{here}} expected-note 2{{candidate}}
671 operator B() volatile;
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
;
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}}
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}}
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
); };
701 void f(Abs
*a
) { foo(*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();
717 template<typename F
> struct Cnvt2
{ Cnvt2(F
); typedef int type
; };
719 // FIXME: We should reject this.
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}}
740 #if __cplusplus >= 201103L
741 namespace dr660
{ // dr660: yes
743 enum class { b
}; // expected-error {{requires a name}}
748 enum class { b
}; // expected-error {{requires a name}}
754 // dr661 FIXME: add codegen test
756 namespace dr662
{ // dr662: yes
757 template <typename T
> void f(T t
) {
759 T
*tp
= &t
; // expected-error {{pointer to a reference}}
760 #if __cplusplus >= 201103L
764 void g(int n
) { f
<int&>(n
); } // expected-note {{instantiation of}}
767 namespace dr663
{ // dr663: sup P1949
771 #if __cplusplus >= 201103L
772 namespace dr664
{ // dr664: yes
773 struct A
{ A(const A
&) = delete; };
774 A
&&f(A
&&a
, int n
) {
776 return f(static_cast<A
&&>(a
), n
- 1);
777 return static_cast<A
&&>(a
);
782 namespace dr665
{ // dr665: yes
783 struct A
{ virtual ~A(); };
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
;
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
; };
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
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; };
828 static_assert(!__is_trivially_destructible(C
), "");
830 struct D
{ D(const D
&) = delete; };
832 static_assert(!__is_trivially_constructible(E
, const E
&), "");
834 struct F
{ F
&operator=(F
&&) = delete; };
836 static_assert(!__is_trivially_assignable(G
, G
&&), "");
840 // dr668 FIXME: add codegen test
842 #if __cplusplus >= 201103L
843 namespace dr669
{ // dr669: yes
846 using T
= decltype(n
);
848 using U
= decltype((n
));
852 using V
= decltype(n
);
854 using W
= decltype((n
));
855 using W
= const int&;
861 using X
= decltype(n
);
863 using Y
= decltype((n
));
864 using Y
= const int&;
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; };
887 enum { e
= X
<struct E
>::n
};
888 void g() { extern struct F
*p
; }
894 F
*f
; // expected-error {{unknown type name}}
897 namespace dr674
{ // dr674: 8
898 template<typename T
> int f(T
);
901 template<typename T
> int g(T
);
904 template<typename T
> int h(T
);
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
; }
920 template int g(int); // expected-note {{in instantiation of}}
925 template<typename T
> int f(T
);
928 template<typename T
> int g(T
);
931 template<typename T
> int h(T
);
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}}
964 namespace dr677
{ // dr677: no
966 void *operator new(std::size_t);
967 void operator delete(void*) = delete; // expected-error 0-1{{C++11}} expected-note {{deleted}}
970 void *operator new(std::size_t);
971 void operator delete(void*) = delete; // expected-error 0-1{{C++11}} expected-note 2{{deleted}}
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
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}}
991 #if __cplusplus >= 201103L
992 namespace dr681
{ // dr681: partial
993 auto *a() -> int; // expected-error {{must specify return type 'auto', not 'auto *'}}
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;
1009 #if __cplusplus >= 201103L
1010 namespace dr683
{ // dr683: yes
1013 A(const A
&) = default;
1016 static_assert(__is_trivially_constructible(A
, const A
&), "");
1017 static_assert(!__is_trivially_constructible(A
, A
&), "");
1018 static_assert(!__is_trivial(A
), "");
1021 static_assert(__is_trivially_constructible(B
, const B
&), "");
1022 static_assert(__is_trivially_constructible(B
, B
&), "");
1023 static_assert(__is_trivial(B
), "");
1027 #if __cplusplus >= 201103L
1028 namespace dr684
{ // dr684: sup 1454
1030 int a
; // expected-note {{here}}
1031 constexpr int *p
= &a
; // expected-error {{constant expression}} expected-note {{pointer to 'a'}}
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}}
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}}
1057 int j(unsigned int); // expected-note {{candidate}}
1058 void j(long); // expected-note {{candidate}}
1059 int d
= j(g
); // expected-error {{ambiguous}}
1067 namespace dr686
{ // dr686: yes
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}}
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 {};
1098 operator struct O
{}(){}; // expected-error {{cannot be defined in a type specifier}}
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}}
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.
1116 #if __cplusplus <= 201703L
1117 // expected-error@-2 {{C++20 extension}}
1121 template g
<int>(a
); // expected-error {{expected expression}}
1125 namespace dr692
{ // dr692: 16
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}}
1141 int &r
= f
<int>(42, &a
);
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
);
1157 // This is made ambiguous by dr692, but made valid again by dr1395.
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
);
1169 short &b
= f(1, 2, 3);
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
1196 const int N
= 10; // expected-note 1+{{here}}
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}}