1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
5 // RUN: %clang_cc1 -std=c++2a -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
7 #if __cplusplus < 201103L
8 // expected-error@+1 {{variadic macro}}
9 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
12 #if __cplusplus >= 201103L
14 typedef decltype(sizeof(int)) size_t;
16 template<typename E
> class initializer_list
{
26 namespace dr1601
{ // dr1601: 10
28 #if __cplusplus < 201103L
29 // expected-error@-2 {{enumeration types with a fixed underlying type are a C++11 extension}}
38 namespace dr1611
{ // dr1611: dup 1658
40 struct B
: virtual A
{ virtual void f() = 0; };
41 struct C
: B
{ C() : A(0) {} void f(); };
45 namespace dr1631
{ // dr1631: 3.7
46 #if __cplusplus >= 201103L
47 // Incorrect overload resolution for single-element initializer-list
49 struct A
{ int a
[1]; };
52 void f(B
, int, int = 0);
56 f({0}, {{1}}); // expected-warning {{braces around scalar init}}
59 namespace with_error
{
60 void f(B
, int); // TODO: expected- note {{candidate function}}
61 void f(int, A
); // expected-note {{candidate function}}
62 void f(int, A
, int = 0); // expected-note {{candidate function}}
65 f({0}, {{1}}); // expected-error{{call to 'f' is ambiguous}}
71 namespace dr1638
{ // dr1638: yes
72 #if __cplusplus >= 201103L
73 template<typename T
> struct A
{
74 enum class E
; // expected-note {{previous}}
75 enum class F
: T
; // expected-note 2{{previous}}
78 template<> enum class A
<int>::E
;
79 template<> enum class A
<int>::E
{};
80 template<> enum class A
<int>::F
: int;
81 template<> enum class A
<int>::F
: int {};
83 template<> enum class A
<short>::E
: int;
84 template<> enum class A
<short>::E
: int {};
86 template<> enum class A
<short>::F
; // expected-error {{different underlying type}}
87 template<> enum class A
<char>::E
: char; // expected-error {{different underlying type}}
88 template<> enum class A
<char>::F
: int; // expected-error {{different underlying type}}
90 enum class A
<unsigned>::E
; // expected-error {{template specialization requires 'template<>'}} expected-error {{nested name specifier}}
91 template enum class A
<unsigned>::E
; // expected-error {{enumerations cannot be explicitly instantiated}}
92 enum class A
<unsigned>::E
*e
; // expected-error {{must use 'enum' not 'enum class'}}
95 friend enum class A
<unsigned>::E
; // expected-error {{must use 'enum' not 'enum class'}}
100 namespace dr1645
{ // dr1645: 3.9
101 #if __cplusplus >= 201103L
103 constexpr A(int, float = 0); // expected-note {{candidate}}
104 explicit A(int, int = 0); // expected-note 2{{candidate}}
105 A(int, int, int = 0) = delete; // expected-note {{candidate}}
109 using A::A
; // expected-note 4{{inherited here}}
112 constexpr B
a(0); // expected-error {{ambiguous}}
113 constexpr B
b(0, 0); // expected-error {{ambiguous}}
117 namespace dr1652
{ // dr1652: 3.6
119 int arr
[&a
+ 1 == &b
? 1 : 2]; // expected-error 2{{variable length array}}
120 // expected-note@-1 {{points past the end}}
123 namespace dr1653
{ // dr1653: 4 c++17
127 #if __cplusplus <= 201402L
128 // expected-warning@-3 {{deprecated}} expected-warning@-2 {{deprecated}}
130 // expected-error@-5 {{incrementing expression of type bool}} expected-error@-4 {{incrementing expression of type bool}}
132 --b
; // expected-error {{cannot decrement expression of type bool}}
133 b
--; // expected-error {{cannot decrement expression of type bool}}
139 namespace dr1658
{ // dr1658: 5
141 class A
{ A(); }; // expected-note 0-2{{here}}
142 class B
{ ~B(); }; // expected-note 0-2{{here}}
144 // The stars align! An abstract class does not construct its virtual bases.
145 struct C
: virtual A
{ C(); virtual void foo() = 0; };
146 C::C() = default; // ok, not deleted, expected-error 0-1{{extension}}
147 struct D
: virtual B
{ D(); virtual void foo() = 0; };
148 D::D() = default; // ok, not deleted, expected-error 0-1{{extension}}
150 // In all other cases, we are not so lucky.
151 struct E
: A
{ E(); virtual void foo() = 0; };
152 #if __cplusplus < 201103L
153 E::E() = default; // expected-error {{private default constructor}} expected-error {{extension}} expected-note {{here}}
155 E::E() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible default constructor}}
157 struct F
: virtual A
{ F(); };
158 #if __cplusplus < 201103L
159 F::F() = default; // expected-error {{private default constructor}} expected-error {{extension}} expected-note {{here}}
161 F::F() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible default constructor}}
164 struct G
: B
{ G(); virtual void foo() = 0; };
165 #if __cplusplus < 201103L
166 G::G() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
168 G::G() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
170 struct H
: virtual B
{ H(); };
171 #if __cplusplus < 201103L
172 H::H() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
174 H::H() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
179 class B
{ ~B(); }; // expected-note 0-2{{here}}
181 struct D
: virtual B
{ ~D(); virtual void foo() = 0; };
182 D::~D() = default; // ok, not deleted, expected-error 0-1{{extension}}
184 struct G
: B
{ ~G(); virtual void foo() = 0; };
185 #if __cplusplus < 201103L
186 G::~G() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
188 G::~G() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
190 struct H
: virtual B
{ ~H(); };
191 #if __cplusplus < 201103L
192 H::~H() = default; // expected-error@-2 {{private destructor}} expected-error {{extension}} expected-note {{here}}
194 H::~H() = default; // expected-error {{would delete}} expected-note@-4{{inaccessible destructor}}
199 struct A
{ A(int); }; // expected-note {{here}}
200 struct B
: virtual A
{
202 virtual void f() = 0;
204 struct C
: virtual A
{
205 C() {} // expected-error {{must explicitly initialize}}
209 namespace CopyCtorParamType
{
211 struct B
: virtual A
{ virtual void f() = 0; };
212 struct C
: virtual A
{ virtual void f(); };
213 struct D
: A
{ virtual void f() = 0; };
216 friend B::B(const B
&) throw();
223 class A
{ A(const A
&); A(A
&&); }; // expected-note 0-4{{here}} expected-error 0-1{{extension}}
225 struct C
: virtual A
{ C(const C
&); C(C
&&); virtual void foo() = 0; }; // expected-error 0-1{{extension}}
226 C::C(const C
&) = default; // expected-error 0-1{{extension}}
227 C::C(C
&&) = default; // expected-error 0-2{{extension}}
229 struct E
: A
{ E(const E
&); E(E
&&); virtual void foo() = 0; }; // expected-error 0-1{{extension}}
230 #if __cplusplus < 201103L
231 E::E(const E
&) = default; // expected-error {{private copy constructor}} expected-error {{extension}} expected-note {{here}}
232 E::E(E
&&) = default; // expected-error {{private move constructor}} expected-error 2{{extension}} expected-note {{here}}
234 E::E(const E
&) = default; // expected-error {{would delete}} expected-note@-5{{inaccessible copy constructor}}
235 E::E(E
&&) = default; // expected-error {{would delete}} expected-note@-6{{inaccessible move constructor}}
237 struct F
: virtual A
{ F(const F
&); F(F
&&); }; // expected-error 0-1{{extension}}
238 #if __cplusplus < 201103L
239 F::F(const F
&) = default; // expected-error {{private copy constructor}} expected-error {{extension}} expected-note {{here}}
240 F::F(F
&&) = default; // expected-error {{private move constructor}} expected-error 2{{extension}} expected-note {{here}}
242 F::F(const F
&) = default; // expected-error {{would delete}} expected-note@-5{{inaccessible copy constructor}}
243 F::F(F
&&) = default; // expected-error {{would delete}} expected-note@-6{{inaccessible move constructor}}
247 // assignment case is superseded by dr2180
250 namespace dr1672
{ // dr1672: 7
253 struct B
{ Empty e
; };
254 struct C
: A
{ B b
; int n
; };
255 struct D
: A
{ int n
; B b
; };
257 static_assert(!__is_standard_layout(C
), "");
258 static_assert(__is_standard_layout(D
), "");
260 struct E
{ B b
; int n
; };
261 struct F
{ int n
; B b
; };
262 union G
{ B b
; int n
; };
263 union H
{ int n
; B b
; };
266 template<typename T
> struct Y
: X
, A
{ T t
; };
268 static_assert(!__is_standard_layout(Y
<E
>), "");
269 static_assert(__is_standard_layout(Y
<F
>), "");
270 static_assert(!__is_standard_layout(Y
<G
>), "");
271 static_assert(!__is_standard_layout(Y
<H
>), "");
272 static_assert(!__is_standard_layout(Y
<X
>), "");
275 namespace dr1684
{ // dr1684: 3.6
276 #if __cplusplus >= 201103L
277 struct NonLiteral
{ // expected-note {{because}}
279 constexpr int f() { return 0; } // expected-warning 0-1{{will not be implicitly 'const'}}
281 constexpr int f(NonLiteral
&) { return 0; }
282 constexpr int f(NonLiteral
) { return 0; } // expected-error {{not a literal type}}
286 namespace dr1687
{ // dr1687: 7
287 template<typename T
> struct To
{
288 operator T(); // expected-note 2{{first operand was implicitly converted to type 'int *'}}
289 // expected-note@-1 {{second operand was implicitly converted to type 'double'}}
290 #if __cplusplus > 201703L
291 // expected-note@-3 2{{operand was implicitly converted to type 'dr1687::E}}
295 int *a
= To
<int*>() + 100.0; // expected-error {{invalid operands to binary expression ('To<int *>' and 'double')}}
296 int *b
= To
<int*>() + To
<double>(); // expected-error {{invalid operands to binary expression ('To<int *>' and 'To<double>')}}
298 #if __cplusplus > 201703L
301 auto c
= To
<E1
>() <=> To
<E2
>(); // expected-error {{invalid operands to binary expression ('To<E1>' and 'To<E2>')}}
305 namespace dr1690
{ // dr1690: 9
306 // See also the various tests in "CXX/basic/basic.lookup/basic.lookup.argdep".
307 #if __cplusplus >= 201103L
309 static auto lambda
= []() { struct S
{} s
; return s
; };
310 void f(decltype(lambda()));
314 auto s
= N::lambda();
320 namespace dr1691
{ // dr1691: 9
321 #if __cplusplus >= 201103L
328 void g(M::E
); // expected-note {{declared here}}
333 g(e
); // expected-error {{use of undeclared}}
338 namespace dr1692
{ // dr1692: 9
353 namespace dr1696
{ // dr1696: 7
354 namespace std_examples
{
355 #if __cplusplus >= 201402L
358 const A
&x
= { A
{a
, a
} };
359 const A
&y
= { A
{} }; // expected-error {{default member initializer for 'y' needed within definition of enclosing class 'A' outside of member functions}} expected-note {{here}}
365 struct A
{ A(); ~A(); };
366 #if __cplusplus >= 201103L
368 A
&&a
; // expected-note {{declared here}}
369 B() : a
{} {} // expected-error {{reference member 'a' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
375 const A
&a
; // expected-note {{declared here}}
377 C::C() : a(A()) {} // expected-error {{reference member 'a' binds to a temporary object whose lifetime would be shorter than the lifetime of the constructed object}}
379 #if __cplusplus >= 201103L
380 // This is OK in C++14 onwards, per DR1815, though we don't support that yet:
384 // ... which lifetime-extends the A temporary.
386 #if __cplusplus < 201402L
387 // expected-error@-2 {{binds to a temporary}}
389 const A
&a
= A(); // expected-note {{default member init}}
392 #if __cplusplus < 201402L
393 // expected-note@-2 {{first required here}}
395 // expected-warning-re@-4 {{sorry, lifetime extension {{.*}} not supported}}
399 const A
&a
= A(); // expected-note {{default member init}}
400 D2() {} // expected-error {{binds to a temporary}}
403 struct D3
{ // expected-error {{binds to a temporary}}
404 const A
&a
= A(); // expected-note {{default member init}}
406 D3 d3
; // expected-note {{first required here}}
409 std::initializer_list
<int> il
; // expected-note {{'std::initializer_list' member}}
410 haslist1(int i
) : il
{i
, 2, 3} {} // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
414 std::initializer_list
<int> il
; // expected-note {{'std::initializer_list' member}}
417 haslist2::haslist2() : il
{1, 2} {} // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
420 std::initializer_list
<int> il
= {1, 2, 3};
423 struct haslist4
{ // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}
424 std::initializer_list
<int> il
= {1, 2, 3}; // expected-note {{default member initializer}}
426 haslist4 hl4
; // expected-note {{in implicit default constructor}}
429 std::initializer_list
<int> il
= {1, 2, 3}; // expected-note {{default member initializer}}
430 haslist5() {} // expected-error {{backing array for 'std::initializer_list' member 'il' is a temporary object}}