Debian Codegraph @

clang/test/CXX/drs/cwg26xx.cpp

raw
1 // RUN: %clang_cc1 -std=c++98 -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected
2 // RUN: %clang_cc1 -std=c++11 -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected,since-cxx11,cxx11
3 // RUN: %clang_cc1 -std=c++14 -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected,since-cxx11
4 // RUN: %clang_cc1 -std=c++17 -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected,since-cxx11
5 // RUN: %clang_cc1 -std=c++20 -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected,since-cxx11,since-cxx20
6 // RUN: %clang_cc1 -std=c++23 -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected,since-cxx11,since-cxx20,since-cxx23
7 // RUN: %clang_cc1 -std=c++2c -triple x86_64-unknown-unknown -pedantic-errors %s -verify=expected,since-cxx11,since-cxx20,since-cxx23
8
9
10 namespace cwg2621 { // cwg2621: sup 2877
11 #if __cplusplus >= 202002L
12 enum class E { a };
13 namespace One {
14 using E_t = E;
15 using enum E_t; // typedef ok
16 auto v = a;
17 }
18 namespace Two {
19 using cwg2621::E;
20 int E; // ignored by type-only lookup
21 using enum E;
22 }
23 #endif
24 }
25
26 namespace cwg2628 { // cwg2628: no
27 // this was reverted for the 16.x release
28 // due to regressions, see the issue for more details:
29 // https://github.com/llvm/llvm-project/issues/60777
30 #if __cplusplus >= 202002L
31 template <bool A = false, bool B = false>
32 struct foo {
33 // The expected notes below should be removed when cwg2628 is fully implemented again
34 constexpr foo() requires (!A && !B) = delete; // #cwg2628-ctor-1
35 constexpr foo() requires (A || B) = delete; // #cwg2628-ctor-2
36 };
37
38 void f() {
39 // The FIXME's below should be the expected errors when cwg2628 is
40 // fully implemented again.
41 foo fooable; // #cwg2628-fooable
42 // since-cxx20-error@-1 {{ambiguous deduction for template arguments of 'foo'}}
43 // since-cxx20-note@#cwg2628-ctor-1 {{candidate function [with A = false, B = false]}}
44 // since-cxx20-note@#cwg2628-ctor-2 {{candidate function [with A = false, B = false]}}
45 // FIXME-since-cxx20-error@#cwg2628-fooable {{call to deleted}}
46 // FIXME-since-cxx20-note@#cwg2628-ctor {{marked deleted here}}
47 }
48 #endif
49 }
50
51 // cwg2630 is in cwg2630.cpp
52
53 namespace cwg2631 { // cwg2631: 16
54 #if __cplusplus >= 202002L
55 constexpr int g();
56 consteval int f() {
57 return g();
58 }
59 int k(int x = f()) {
60 return x;
61 }
62 constexpr int g() {
63 return 42;
64 }
65 int test() {
66 return k();
67 }
68 #endif
69 }
70
71 namespace cwg2635 { // cwg2635: 16
72 #if __cplusplus >= 202002L
73 template<typename T>
74 concept UnaryC = true;
75 template<typename T, typename U>
76 concept BinaryC = true;
77
78 struct S{ int i, j; };
79 S get_S();
80
81 template<typename T>
82 T get_T();
83
84 void use() {
85 UnaryC auto [a, b] = get_S();
86 // since-cxx20-error@-1 {{decomposition declaration cannot be declared with constrained 'auto'}}
87 BinaryC<int> auto [c, d] = get_S();
88 // since-cxx20-error@-1 {{decomposition declaration cannot be declared with constrained 'auto'}}
89 }
90
91 template<typename T>
92 void TemplUse() {
93 UnaryC auto [a, b] = get_T<T>();
94 // since-cxx20-error@-1 {{decomposition declaration cannot be declared with constrained 'auto'}}
95 BinaryC<T> auto [c, d] = get_T<T>();
96 // since-cxx20-error@-1 {{decomposition declaration cannot be declared with constrained 'auto'}}
97 }
98 #endif
99 }
100
101 // cwg2636: na
102
103 namespace cwg2640 { // cwg2640: 16
104
105 int \N{Λ} = 0;
106 // expected-error@-1 {{'Λ' is not a valid Unicode character name}}
107 // expected-error@-2 {{expected unqualified-id}}
108 const char* emoji = "\N{🤡}";
109 // expected-error@-1 {{'🤡' is not a valid Unicode character name}}
110 // expected-note@-2 {{did you mean OX ('🐂' U+1F402)?}}
111 // expected-note@-3 {{did you mean ANT ('🐜' U+1F41C)?}}
112 // expected-note@-4 {{did you mean ARC ('⌒' U+2312)?}}
113 // expected-note@-5 {{did you mean AXE ('🪓' U+1FA93)?}}
114 // expected-note@-6 {{did you mean BAT ('🦇' U+1F987)?}}
115
116 #define z(x) 0
117 #define cwg2640_a z(
118 int x = cwg2640_a\N{abc});
119 // expected-error@-1 {{'abc' is not a valid Unicode character name}}
120 int y = cwg2640_a\N{LOTUS});
121 // expected-error@-1 {{character <U+1FAB7> not allowed in an identifier}}
122 // expected-error@-2 {{use of undeclared identifier 'cwg2640_a🪷'}}
123 // expected-error@-3 {{extraneous ')' before ';'}}
124 }
125
126 // cwg2642: na
127
128 namespace cwg2644 { // cwg2644: 8
129 #if __cplusplus >= 201103L
130 auto z = [a = 42](int a) {
131 // cxx11-error@-1 {{initialized lambda captures are a C++14 extension}}
132 // since-cxx11-error@-2 {{a lambda parameter cannot shadow an explicitly captured entity}}
133 // since-cxx11-note@-3 {{variable 'a' is explicitly captured here}}
134 return 1;
135 };
136 #endif
137 }
138
139 #if __cplusplus >= 202302L
140 namespace cwg2650 { // cwg2650: 17
141 template <class T, T> struct S {};
142 template <class T> int f(S<T, T{}>*); // #cwg2650-f
143 class X {
144 int m;
145 };
146 int i0 = f<X>(0);
147 // since-cxx23-error@-1 {{no matching function for call to 'f'}}
148 // since-cxx23-note@#cwg2650-f {{type 'X' of non-type template parameter is not a structural type}}
149 }
150 #endif
151
152 #if __cplusplus >= 202302L
153 namespace cwg2653 { // cwg2653: 18
154 struct Test { void f(this const auto& = Test{}); };
155 // since-cxx23-error@-1 {{the explicit object parameter cannot have a default argument}}
156 auto L = [](this const auto& = Test{}){};
157 // since-cxx23-error@-1 {{the explicit object parameter cannot have a default argument}}
158 }
159 #endif
160
161 namespace cwg2654 { // cwg2654: 16
162 void f() {
163 int neck, tail;
164 volatile int brachiosaur;
165 brachiosaur += neck; // OK
166 brachiosaur -= neck; // OK
167 brachiosaur |= neck; // OK
168 }
169 }
170
171 namespace cwg2681 { // cwg2681: 17
172 #if __cplusplus >= 202002L
173 using size_t = decltype(sizeof(int));
174
175 template<class T, size_t N>
176 struct H {
177 T array[N];
178 };
179 template<class T, size_t N>
180 struct I {
181 volatile T array[N];
182 };
183 template<size_t N>
184 struct J { // #cwg2681-J
185 unsigned char array[N];
186 };
187
188 H h = { "abc" };
189 I i = { "def" };
190 static_assert(__is_same(decltype(h), H<char, 4>)); // Not H<const char, 4>
191 static_assert(__is_same(decltype(i), I<char, 4>));
192
193 J j = { "ghi" };
194 // since-cxx20-error@-1 {{no viable constructor or deduction guide}}
195 // since-cxx20-note@#cwg2681-J {{candidate template ignored: could not match 'J<N>' against 'const char *'}}
196 // since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template <size_t N> J(J<N>) -> J<N>'}}
197 // since-cxx20-note@#cwg2681-J {{candidate template ignored: could not match 'const unsigned char' against 'const char'}}
198 // since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template <size_t N> J(const unsigned char (&)[N]) -> J<N>'}}
199 // since-cxx20-note@#cwg2681-J {{candidate function template not viable: requires 0 arguments, but 1 was provided}}
200 // since-cxx20-note@#cwg2681-J {{implicit deduction guide declared as 'template <size_t N> J() -> J<N>'}}
201 #endif
202 }
203
204 namespace cwg2672 { // cwg2672: 18
205 #if __cplusplus >= 202002L
206 template <class T>
207 void f(T) requires requires { []() { T::invalid; } (); };
208 // since-cxx20-error@-1 {{type 'int' cannot be used prior to '::' because it has no members}}
209 // since-cxx20-note@-2 {{while substituting into a lambda expression here}}
210 // since-cxx20-note@-3 {{in instantiation of requirement here}}
211 // since-cxx20-note@-4 {{while substituting template arguments into constraint expression here}}
212 // since-cxx20-note@#cwg2672-f-0 {{while checking constraint satisfaction for template 'f<int>' required here}}
213 // since-cxx20-note@#cwg2672-f-0 {{in instantiation of function template specialization 'cwg2672::f<int>' requested here}}
214 void f(...);
215
216 template <class T>
217 void bar(T) requires requires {
218 []() -> decltype(T::foo()) {};
219 };
220 void bar(...);
221
222 void m() {
223 f(0); // #cwg2672-f-0
224 bar(0);
225 }
226 #endif
227 }
228
229 #if __cplusplus >= 202302L
230 namespace cwg2687 { // cwg2687: 18
231 struct S{
232 void f(int);
233 static void g(int);
234 void h(this const S&, int);
235 };
236
237 void test() {
238 (&S::f)(1);
239 // since-cxx23-error@-1 {{called object type 'void (cwg2687::S::*)(int)' is not a function or function pointer}}
240 (&S::g)(1);
241 (&S::h)(S(), 1);
242 }
243 }
244 #endif
245
246
247 namespace cwg2692 { // cwg2692: 19
248 #if __cplusplus >= 202302L
249
250 struct A {
251 static void f(A); // #cwg2692-1
252 void f(this A); // #cwg2692-2
253
254 void g();
255 };
256
257 void A::g() {
258 (&A::f)(A());
259 // expected-error@-1 {{call to 'f' is ambiguous}}
260 // expected-note@#cwg2692-1 {{candidate}}
261 // expected-note@#cwg2692-2 {{candidate}}
262
263
264
265 (&A::f)();
266 // expected-error@-1 {{no matching function for call to 'f'}}
267 // expected-note@#cwg2692-1 {{candidate function not viable: requires 1 argument, but 0 were provided}}
268 // expected-note@#cwg2692-2 {{candidate function not viable: requires 1 argument, but 0 were provided}}
269 }
270 #endif
271 }