Run DCE after a LoopFlatten test to reduce spurious output [nfc]
[llvm-project.git] / clang / test / CXX / drs / dr25xx.cpp
blob3644e4c328b1bcbcab69b5d494eb6794d50e05b2
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
11 #endif
13 namespace dr2516 { // dr2516: yes
14 // NB: reusing 1482 test
15 #if __cplusplus >= 201103L
16 template <typename T> struct S {
17 typedef char I;
19 enum E2 : S<E2>::I { e };
20 // expected-error@-1 {{use of undeclared identifier 'E2'}}
21 #endif
22 } // namespace dr2516
24 namespace dr2518 { // dr2518: 17
26 #if __cplusplus >= 201103L
27 template <class T>
28 void f(T t) {
29 if constexpr (sizeof(T) != sizeof(int)) {
30 #if __cplusplus < 201703L
31 // expected-error@-2 {{constexpr if is a C++17 extension}}
32 #endif
33 static_assert(false, "must be int-sized"); // expected-error {{must be int-size}}
37 void g(char c) {
38 f(0);
39 f(c); // expected-note {{requested here}}
42 template <typename Ty>
43 struct S {
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}}
47 #endif
50 template <>
51 struct S<int> {};
53 template <>
54 struct S<float> {};
56 int test_specialization() {
57 S<int> s1;
58 S<float> s2;
59 S<double> s3; // expected-note {{in instantiation of template class 'dr2518::S<double>' requested here}}
61 #endif
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)
74 operator"" _div();
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
81 #endif
82 } // namespace dr2521
85 #if __cplusplus >= 202302L
86 namespace dr2553 { // dr2553: 18
87 struct B {
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}}
92 struct D : B {
93 void g(this D&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
97 #endif
99 #if __cplusplus >= 202302L
100 namespace dr2554 { // dr2554: 18 review
101 struct B {
102 virtual void f(); // expected-note 3{{here}}
105 struct D : B {
106 void f(this D&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
109 struct D2 : B {
110 void f(this B&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
112 struct T {};
113 struct D3 : B {
114 void f(this T&); // expected-error {{an explicit object parameter cannot appear in a virtual function}}
118 #endif
120 #if __cplusplus >= 202302L
121 namespace dr2561 { // dr2561: 18 review
122 struct C {
123 constexpr C(auto) { }
125 void foo() {
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);
133 #endif
136 namespace dr2565 { // dr2565: 16
137 #if __cplusplus >= 202002L
138 template<typename T>
139 concept C = requires (typename T::type x) {
140 x + 1;
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; };
148 template<typename T>
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}}
179 template<typename T>
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}}
188 template<typename T>
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}}
199 #endif