1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
8 #if __cplusplus < 201103L
9 // expected-error@+1 {{variadic macro}}
10 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
13 namespace dr2100
{ // dr2100: 12
14 template<const int *P
, bool = true> struct X
{};
15 template<typename T
> struct A
{
16 static const int n
= 1;
18 return X
<&n
>::n
; // ok, value-dependent
21 static const int n
= 2;
22 return X
<&n
>::n
; // ok, value-dependent
23 #if __cplusplus < 201702L
24 // expected-error@-2 {{does not have linkage}} expected-note@-3 {{here}}
28 template<const int *P
> struct X
<P
> {
29 #if __cplusplus < 201103L
30 static const int n
= 0;
32 static const int n
= *P
;
35 int q
= A
<int>().f() + A
<int>().g();
37 // Corresponding constructs where the address is not taken are not
39 template<int N
, bool = true> struct Y
{};
40 template<typename T
> struct B
{
41 static const int n
= 1;
43 return Y
<n
>::declared_later
; // expected-error {{no member named 'declared_later'}}
46 static const int n
= 2;
47 return Y
<n
>::declared_later
; // expected-error {{no member named 'declared_later'}}
50 template<int N
> struct Y
<N
> {
51 static const int declared_later
= 0;
55 namespace dr2103
{ // dr2103: yes
58 int &r
= a
; // expected-note {{here}}
61 int &s
= r
; // expected-error {{enclosing function}}
68 namespace dr2120
{ // dr2120: 7
73 struct E
: B
{ D d
; };
74 static_assert(__is_standard_layout(B
), "");
75 static_assert(__is_standard_layout(D
), "");
76 static_assert(!__is_standard_layout(E
), "");
79 namespace dr2126
{ // dr2126: 12
80 #if __cplusplus >= 201103L
83 const A
&a
= {1}; // const temporary
84 A
&b
= (A
&)(const A
&)A
{1}; // const temporary
85 A
&&c
= (A
&&)(const A
&)A
{1}; // const temporary
87 A
&&d
= {1}; // non-const temporary expected-note {{here}}
88 const A
&e
= (A
&)(A
&&) A
{1}; // non-const temporary expected-note {{here}}
89 A
&&f
= (A
&&)(A
&&) A
{1}; // non-const temporary expected-note {{here}}
91 constexpr const A
&g
= {1}; // const temporary
92 constexpr A
&&h
= {1}; // non-const temporary expected-note {{here}}
94 struct B
{ const A
&a
; };
95 B i
= {{1}}; // extending decl not usable in constant expr expected-note {{here}}
96 const B j
= {{1}}; // extending decl not usable in constant expr expected-note {{here}}
97 constexpr B k
= {{1}}; // extending decl usable in constant expr
99 static_assert(a
.n
== 1, "");
100 static_assert(b
.n
== 1, "");
101 static_assert(c
.n
== 1, "");
102 static_assert(d
.n
== 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
103 static_assert(e
.n
== 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
104 static_assert(f
.n
== 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
105 static_assert(g
.n
== 1, "");
106 static_assert(h
.n
== 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
107 static_assert(i
.a
.n
== 1, ""); // expected-error {{constant}} expected-note {{read of non-constexpr variable}}
108 static_assert(j
.a
.n
== 1, ""); // expected-error {{constant}} expected-note {{read of temporary}}
109 static_assert(k
.a
.n
== 1, "");
113 namespace dr2140
{ // dr2140: 9
114 #if __cplusplus >= 201103L
115 union U
{ int a
; decltype(nullptr) b
; };
116 constexpr int *test(U u
) {
119 static_assert(!test({123}), "u.b should be valid even when b is inactive");
123 namespace dr2141
{ // dr2141: 17
126 template <typename T
>
130 struct A
*b
= (1 == 1) ? new struct A
: new struct A
;
131 struct S
*a
= (1 == 1) ? new struct S
: new struct S
; // expected-error 2{{allocation of incomplete type}} // expected-note 2{{forward}}
133 #if __cplusplus >= 201103L
134 A
*aa
= new struct A
{};
135 B
<int> *bb
= new struct B
<int>{};
136 (void)new struct C
{}; // expected-error {{allocation of incomplete type }} // expected-note {{forward}}
138 struct A
*c
= (1 == 1) ? new struct A
{} : new struct A
{};
140 alignof(struct D
{}); // expected-error {{cannot be defined in a type specifier}}
143 sizeof(struct E
{}); // expected-error {{cannot be defined in a type specifier}}
148 namespace dr2157
{ // dr2157: 11
149 #if __cplusplus >= 201103L
152 enum dr2157::E
: int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
159 namespace dr2170
{ // dr2170: 9
160 #if __cplusplus >= 201103L
162 constexpr int arr
[3] = {1, 2, 3}; // expected-note {{here}}
164 int get(int n
) { return arr
[n
]; }
165 const int &get_ref(int n
) { return arr
[n
]; } // expected-error {{enclosing function}}
166 // FIXME: expected-warning@-1 {{reference to stack}}
172 namespace dr2171
{ // dr2171: 15
173 #if __cplusplus >= 201103L
175 struct NonConstCopy
{
176 NonConstCopy(NonConstCopy
&) = default;
177 NonConstCopy
&operator=(NonConstCopy
&) = default;
180 static_assert(__has_trivial_copy(NonConstCopy
), "");
181 static_assert(__is_trivially_constructible(NonConstCopy
, NonConstCopy
&), "");
182 static_assert(!__is_trivially_constructible(NonConstCopy
, NonConstCopy
), "");
183 static_assert(!__is_trivially_constructible(NonConstCopy
, const NonConstCopy
&), "");
184 static_assert(!__is_trivially_constructible(NonConstCopy
, NonConstCopy
&&), "");
186 static_assert(__has_trivial_assign(NonConstCopy
), "");
187 static_assert(__is_trivially_assignable(NonConstCopy
&, NonConstCopy
&), "");
188 static_assert(!__is_trivially_assignable(NonConstCopy
&, const NonConstCopy
&), "");
189 static_assert(!__is_trivially_assignable(NonConstCopy
&, NonConstCopy
), "");
190 static_assert(!__is_trivially_assignable(NonConstCopy
&, NonConstCopy
&&), "");
191 static_assert(__is_trivially_assignable(NonConstCopy
&&, NonConstCopy
&), "");
192 static_assert(!__is_trivially_assignable(NonConstCopy
&&, const NonConstCopy
&), "");
193 static_assert(!__is_trivially_assignable(NonConstCopy
&&, NonConstCopy
), "");
194 static_assert(!__is_trivially_assignable(NonConstCopy
&&, NonConstCopy
&&), "");
197 } // namespace dr2171
199 namespace dr2180
{ // dr2180: yes
201 A
&operator=(const A
&); // expected-note 0-2{{here}}
202 A
&operator=(A
&&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
205 struct B
: virtual A
{
206 B
&operator=(const B
&);
207 B
&operator=(B
&&); // expected-error 0-1{{extension}}
208 virtual void foo() = 0;
210 #if __cplusplus < 201103L
211 B
&B::operator=(const B
&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
212 B
&B::operator=(B
&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
214 B
&B::operator=(const B
&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
215 B
&B::operator=(B
&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
219 namespace dr2199
{ // dr2199: 3.8
220 // NB: reusing part of dr407 test