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
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -Wno-deprecated-builtins -fcxx-exceptions -pedantic-errors
9 #if __cplusplus < 201103L
10 // expected-error@+1 {{variadic macro}}
11 #define static_assert(...) __extension__ _Static_assert(__VA_ARGS__)
14 namespace dr1812
{ // dr1812: no
16 #if __cplusplus >= 201103L
17 template <typename T
> struct A
{
18 using B
= typename
T::C
<int>;
19 // expected-error@-1 {{use 'template' keyword to treat 'C' as a dependent template name}}
24 namespace dr1813
{ // dr1813: 7
28 struct E
: D
{ char : 4; };
30 static_assert(__is_standard_layout(B
), "");
31 static_assert(__is_standard_layout(C
), "");
32 static_assert(__is_standard_layout(D
), "");
33 static_assert(!__is_standard_layout(E
), "");
40 static_assert(__is_standard_layout(Q
), "");
41 static_assert(__is_standard_layout(S
), "");
42 static_assert(__is_standard_layout(T
), "");
43 static_assert(!__is_standard_layout(U
), "");
46 namespace dr1814
{ // dr1814: yes
47 #if __cplusplus >= 201103L
49 auto lam
= [](int x
= 42) { return x
; };
54 namespace dr1815
{ // dr1815: no
55 #if __cplusplus >= 201402L
56 // FIXME: needs codegen test
57 struct A
{ int &&r
= 0; }; // expected-note {{default member init}}
58 A a
= {}; // FIXME expected-warning {{not supported}}
60 struct B
{ int &&r
= 0; }; // expected-error {{binds to a temporary}} expected-note {{default member init}}
61 B b
; // expected-note {{here}}
65 namespace dr1821
{ // dr1821: yes
67 template <typename
> struct B
{
70 template <typename T
> void B
<T
>::f(){};
71 // expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}}
77 // expected-error@-1 {{non-friend class member 'f' cannot have a qualified name}}
81 namespace dr1822
{ // dr1822: yes
82 #if __cplusplus >= 201103L
85 #pragma clang __debug dump a // CHECK: ParmVarDecl
90 namespace dr1837
{ // dr1837: 3.3
91 #if __cplusplus >= 201103L
93 struct Fish
{ static const bool value
= true; };
97 auto q() -> decltype(p()) *;
101 friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
104 extern void f(decltype(this->g()) *);
106 static_assert(Fish
<decltype(this->g())>::value
, ""); // expected-error {{invalid use of 'this'}}
107 enum { X
= Fish
<decltype(this->f())>::value
}; // expected-error {{invalid use of 'this'}}
108 struct Inner2
: Fish
<decltype(this->g())> { }; // expected-error {{invalid use of 'this'}}
109 friend void f(decltype(this->g()) *); // expected-error {{invalid use of 'this'}}
110 friend auto Other::q() -> decltype(this->p()) *; // expected-error {{invalid use of 'this'}}
120 static_assert(sizeof(this->f()) == sizeof(int), "");
127 namespace dr1872
{ // dr1872: 9
128 #if __cplusplus >= 201103L
129 template<typename T
> struct A
: T
{
130 constexpr int f() const { return 0; }
133 struct Y
{ virtual int f() const; };
134 struct Z
: virtual X
{};
136 constexpr int x
= A
<X
>().f();
137 constexpr int y
= A
<Y
>().f();
138 #if __cplusplus <= 201703L
139 // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
141 static_assert(y
== 0);
143 // Note, this is invalid even though it would not use virtual dispatch.
144 constexpr int y2
= A
<Y
>().A
<Y
>::f();
145 #if __cplusplus <= 201703L
146 // expected-error@-2 {{constant expression}} expected-note@-2 {{call to virtual function}}
148 static_assert(y
== 0);
150 constexpr int z
= A
<Z
>().f(); // expected-error {{constant expression}} expected-note {{non-literal type}}
154 namespace dr1881
{ // dr1881: 7
155 struct A
{ int a
: 4; };
156 struct B
: A
{ int b
: 3; };
157 static_assert(__is_standard_layout(A
), "");
158 static_assert(!__is_standard_layout(B
), "");
160 struct C
{ int : 0; };
161 struct D
: C
{ int : 0; };
162 static_assert(__is_standard_layout(C
), "");
163 static_assert(!__is_standard_layout(D
), "");
166 void dr1891() { // dr1891: 4
167 #if __cplusplus >= 201103L
169 auto a
= []{}; // expected-note 0-4{{}}
170 auto b
= [=]{ return n
; }; // expected-note 0-4{{}}
171 typedef decltype(a
) A
;
172 typedef decltype(b
) B
;
174 static_assert(!__has_trivial_constructor(A
), "");
175 #if __cplusplus > 201703L
176 // expected-error@-2 {{failed}}
178 static_assert(!__has_trivial_constructor(B
), "");
180 // C++20 allows default construction for non-capturing lambdas (P0624R2).
182 #if __cplusplus <= 201703L
183 // expected-error@-2 {{no matching constructor}}
185 B y
; // expected-error {{no matching constructor}}
187 // C++20 allows assignment for non-capturing lambdas (P0624R2).
189 a
= static_cast<A
&&>(a
);
190 #if __cplusplus <= 201703L
191 // expected-error@-3 {{copy assignment operator is implicitly deleted}}
192 // expected-error@-3 {{copy assignment operator is implicitly deleted}}
194 b
= b
; // expected-error {{copy assignment operator is implicitly deleted}}
195 b
= static_cast<B
&&>(b
); // expected-error {{copy assignment operator is implicitly deleted}}
199 namespace dr1894
{ // dr1894: 3.8
200 // NB: reusing part of dr407 test