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++20 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown %s -verify -fexceptions -fcxx-exceptions -pedantic-errors
9 #if __cplusplus < 201103L
10 // expected-no-diagnostics
13 namespace dr2516
{ // dr2516: yes
14 // NB: reusing 1482 test
15 #if __cplusplus >= 201103L
16 template <typename T
> struct S
{
19 enum E2
: S
<E2
>::I
{ e
};
20 // expected-error@-1 {{use of undeclared identifier 'E2'}}
24 namespace dr2518
{ // dr2518: 17
26 #if __cplusplus >= 201103L
29 if constexpr (sizeof(T
) != sizeof(int)) {
30 #if __cplusplus < 201703L
31 // expected-error@-2 {{constexpr if is a C++17 extension}}
33 static_assert(false, "must be int-sized"); // expected-error {{must be int-size}}
39 f(c
); // expected-note {{requested here}}
42 template <typename Ty
>
44 static_assert(false); // expected-error {{static assertion failed}}
45 #if __cplusplus < 201703L
46 // expected-error@-2 {{'static_assert' with no message is a C++17 extension}}
56 int test_specialization() {
59 S
<double> s3
; // expected-note {{in instantiation of template class 'dr2518::S<double>' requested here}}
65 namespace dr2521
{ // dr2521: 17
66 #if __cplusplus >= 201103L
67 #pragma clang diagnostic push
68 #pragma clang diagnostic warning "-Wdeprecated-literal-operator"
69 long double operator"" _
\u03C0___
(long double);
70 // expected-warning@-1 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
71 // expected-warning@-2 {{user-defined literal suffixes containing '__' are reserved}}
73 template <char... Chars
> decltype(sizeof 0)
75 // expected-warning@-1 {{identifier '_div' preceded by whitespace in a literal operator declaration is deprecated}}
77 using ::dr2521::operator"" _
\u03C0___
;
78 using ::dr2521::operator""_div
;
79 // expected-warning@-2 {{identifier '_π___' preceded by whitespace in a literal operator declaration is deprecated}}
80 #pragma clang diagnostic pop
85 #if __cplusplus >= 202302L
86 namespace dr2553
{ // dr2553: 18
88 virtual void f(this B
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
89 static void f(this B
&); // expected-error {{an explicit object parameter cannot appear in a static function}}
90 virtual void g(); // expected-note {{here}}
93 void g(this D
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
99 #if __cplusplus >= 202302L
100 namespace dr2554
{ // dr2554: 18 review
102 virtual void f(); // expected-note 3{{here}}
106 void f(this D
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
110 void f(this B
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
114 void f(this T
&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
120 #if __cplusplus >= 202302L
121 namespace dr2561
{ // dr2561: 18 review
123 constexpr C(auto) { }
126 constexpr auto b
= [](this C
) { return 1; };
127 constexpr int (*fp
)(C
) = b
;
128 static_assert(fp(1) == 1);
129 static_assert((&decltype(b
)::operator())(1) == 1);
136 namespace dr2565
{ // dr2565: 16
137 #if __cplusplus >= 202002L
139 concept C
= requires (typename
T::type x
) {
142 static_assert(!C
<int>);
144 // Variant of this as reported in GH57487.
145 template<bool B
> struct bool_constant
146 { static constexpr bool value
= B
; };
149 using is_referenceable
150 = bool_constant
<requires (T
&) { true; }>;
152 static_assert(!is_referenceable
<void>::value
);
153 static_assert(is_referenceable
<int>::value
);
155 template<typename T
, typename U
>
156 concept TwoParams
= requires (T
*a
, U b
){ true;}; // #TPC
158 template<typename T
, typename U
>
159 requires TwoParams
<T
, U
> // #TPSREQ
160 struct TwoParamsStruct
{};
162 using TPSU
= TwoParamsStruct
<void, void>;
163 // expected-error@-1{{constraints not satisfied for class template 'TwoParamsStruct'}}
164 // expected-note@#TPSREQ{{because 'TwoParams<void, void>' evaluated to false}}
165 // expected-note@#TPC{{because 'b' would be invalid: argument may not have 'void' type}}
167 template<typename T
, typename
...U
>
168 concept Variadic
= requires (U
* ... a
, T b
){ true;}; // #VC
170 template<typename T
, typename
...U
>
171 requires Variadic
<T
, U
...> // #VSREQ
172 struct VariadicStruct
{};
174 using VSU
= VariadicStruct
<void, int, char, double>;
175 // expected-error@-1{{constraints not satisfied for class template 'VariadicStruct'}}
176 // expected-note@#VSREQ{{because 'Variadic<void, int, char, double>' evaluated to false}}
177 // expected-note@#VC{{because 'b' would be invalid: argument may not have 'void' type}}
180 // expected-error@+1 {{unknown type name 'ErrorRequires'}}
181 concept ErrorRequires
= requires (ErrorRequires
auto x
) {
184 static_assert(ErrorRequires
<int>);
185 // expected-error@-1{{static assertion failed}}
186 // expected-note@-2{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}
189 // expected-error@+2 {{unknown type name 'NestedErrorInRequires'}}
190 concept NestedErrorInRequires
= requires (T x
) {
191 requires
requires (NestedErrorInRequires
auto y
) {
195 static_assert(NestedErrorInRequires
<int>);
196 // expected-error@-1{{static assertion failed}}
197 // expected-note@-2{{because substituted constraint expression is ill-formed: constraint depends on a previously diagnosed expression}}