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 dr2157
{ // dr2157: 11
124 #if __cplusplus >= 201103L
127 enum dr2157::E
: int(); // expected-error {{only allows ':' in member enumeration declaration to introduce a fixed underlying type}}
134 namespace dr2170
{ // dr2170: 9
135 #if __cplusplus >= 201103L
137 constexpr int arr
[3] = {1, 2, 3}; // expected-note {{here}}
139 int get(int n
) { return arr
[n
]; }
140 const int &get_ref(int n
) { return arr
[n
]; } // expected-error {{enclosing function}}
141 // FIXME: expected-warning@-1 {{reference to stack}}
147 namespace dr2171
{ // dr2171: 15
148 #if __cplusplus >= 201103L
150 struct NonConstCopy
{
151 NonConstCopy(NonConstCopy
&) = default;
152 NonConstCopy
&operator=(NonConstCopy
&) = default;
155 static_assert(__has_trivial_copy(NonConstCopy
), "");
156 static_assert(__is_trivially_constructible(NonConstCopy
, NonConstCopy
&), "");
157 static_assert(!__is_trivially_constructible(NonConstCopy
, NonConstCopy
), "");
158 static_assert(!__is_trivially_constructible(NonConstCopy
, const NonConstCopy
&), "");
159 static_assert(!__is_trivially_constructible(NonConstCopy
, NonConstCopy
&&), "");
161 static_assert(__has_trivial_assign(NonConstCopy
), "");
162 static_assert(__is_trivially_assignable(NonConstCopy
&, NonConstCopy
&), "");
163 static_assert(!__is_trivially_assignable(NonConstCopy
&, const NonConstCopy
&), "");
164 static_assert(!__is_trivially_assignable(NonConstCopy
&, NonConstCopy
), "");
165 static_assert(!__is_trivially_assignable(NonConstCopy
&, NonConstCopy
&&), "");
166 static_assert(__is_trivially_assignable(NonConstCopy
&&, NonConstCopy
&), "");
167 static_assert(!__is_trivially_assignable(NonConstCopy
&&, const NonConstCopy
&), "");
168 static_assert(!__is_trivially_assignable(NonConstCopy
&&, NonConstCopy
), "");
169 static_assert(!__is_trivially_assignable(NonConstCopy
&&, NonConstCopy
&&), "");
172 } // namespace dr2171
174 namespace dr2180
{ // dr2180: yes
176 A
&operator=(const A
&); // expected-note 0-2{{here}}
177 A
&operator=(A
&&); // expected-note 0-2{{here}} expected-error 0-1{{extension}}
180 struct B
: virtual A
{
181 B
&operator=(const B
&);
182 B
&operator=(B
&&); // expected-error 0-1{{extension}}
183 virtual void foo() = 0;
185 #if __cplusplus < 201103L
186 B
&B::operator=(const B
&) = default; // expected-error {{private member}} expected-error {{extension}} expected-note {{here}}
187 B
&B::operator=(B
&&) = default; // expected-error {{private member}} expected-error 2{{extension}} expected-note {{here}}
189 B
&B::operator=(const B
&) = default; // expected-error {{would delete}} expected-note@-9{{inaccessible copy assignment}}
190 B
&B::operator=(B
&&) = default; // expected-error {{would delete}} expected-note@-10{{inaccessible move assignment}}
194 namespace dr2199
{ // dr2199: 3.8
195 // NB: reusing part of dr407 test