Skip to content

Commit f53abc2

Browse files
committed
[clang][NFC] Refactor expected directives in CWG2881 test
1 parent 743c84b commit f53abc2

File tree

1 file changed

+41
-23
lines changed

1 file changed

+41
-23
lines changed

clang/test/CXX/drs/cwg28xx.cpp

Lines changed: 41 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -174,9 +174,7 @@ void g() {
174174
} // namespace cwg2877
175175

176176
namespace cwg2881 { // cwg2881: 19
177-
178177
#if __cplusplus >= 202302L
179-
180178
template <typename T> struct A : T {};
181179
template <typename T> struct B : T {};
182180
template <typename T> struct C : virtual T { C(T t) : T(t) {} };
@@ -188,12 +186,12 @@ struct O1 : A<Ts>, B<Ts> {
188186
using B<Ts>::operator();
189187
};
190188

191-
template <typename Ts> struct O2 : protected Ts { // expected-note {{declared protected here}}
189+
template <typename Ts> struct O2 : protected Ts { // #cwg2881-O2
192190
using Ts::operator();
193191
O2(Ts ts) : Ts(ts) {}
194192
};
195193

196-
template <typename Ts> struct O3 : private Ts { // expected-note {{declared private here}}
194+
template <typename Ts> struct O3 : private Ts { // #cwg2881-O3
197195
using Ts::operator();
198196
O3(Ts ts) : Ts(ts) {}
199197
};
@@ -217,7 +215,7 @@ struct O5 : private C<Ts>, D<Ts> {
217215

218216
// This is only invalid if we call T's call operator.
219217
template <typename T, typename U>
220-
struct O6 : private T, U { // expected-note {{declared private here}}
218+
struct O6 : private T, U { // #cwg2881-O6
221219
using T::operator();
222220
using U::operator();
223221
O6(T t, U u) : T(t), U(u) {}
@@ -227,14 +225,26 @@ void f() {
227225
int x;
228226
auto L1 = [=](this auto&& self) { (void) &x; };
229227
auto L2 = [&](this auto&& self) { (void) &x; };
230-
O1<decltype(L1)>{L1, L1}(); // expected-error {{inaccessible due to ambiguity}}
231-
O1<decltype(L2)>{L2, L2}(); // expected-error {{inaccessible due to ambiguity}}
232-
O2{L1}(); // expected-error {{must derive publicly from the lambda}}
233-
O3{L1}(); // expected-error {{must derive publicly from the lambda}}
228+
O1<decltype(L1)>{L1, L1}();
229+
/* since-cxx23-error-re@-1 {{inaccessible due to ambiguity:
230+
struct cwg2881::O1<class (lambda at {{.+}})> -> A<(lambda at {{.+}})> -> class (lambda at {{.+}})
231+
struct cwg2881::O1<class (lambda at {{.+}})> -> B<(lambda at {{.+}})> -> class (lambda at {{.+}})}}*/
232+
O1<decltype(L2)>{L2, L2}();
233+
/* since-cxx23-error-re@-1 {{inaccessible due to ambiguity:
234+
struct cwg2881::O1<class (lambda at {{.+}})> -> A<(lambda at {{.+}})> -> class (lambda at {{.+}})
235+
struct cwg2881::O1<class (lambda at {{.+}})> -> B<(lambda at {{.+}})> -> class (lambda at {{.+}})}}*/
236+
O2{L1}();
237+
// since-cxx23-error-re@-1 {{invalid explicit object parameter type 'cwg2881::O2<(lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}
238+
// since-cxx23-note@#cwg2881-O2 {{declared protected here}}
239+
O3{L1}();
240+
// since-cxx23-error-re@-1 {{invalid explicit object parameter type 'cwg2881::O3<(lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}
241+
// since-cxx23-note@#cwg2881-O3 {{declared private here}}
234242
O4{L1}();
235243
O5{L1}();
236244
O6 o{L1, L2};
237-
o.decltype(L1)::operator()(); // expected-error {{must derive publicly from the lambda}}
245+
o.decltype(L1)::operator()();
246+
// since-cxx23-error-re@-1 {{invalid explicit object parameter type 'cwg2881::O6<(lambda at {{.+}}), (lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}
247+
// since-cxx23-note@#cwg2881-O6 {{declared private here}}
238248
o.decltype(L1)::operator()(); // No error here because we've already diagnosed this method.
239249
o.decltype(L2)::operator()();
240250
}
@@ -243,12 +253,14 @@ void f2() {
243253
int x = 0;
244254
auto lambda = [x] (this auto self) { return x; };
245255
using Lambda = decltype(lambda);
246-
struct D : private Lambda { // expected-note {{declared private here}}
256+
struct D : private Lambda { // #cwg2881-D
247257
D(Lambda l) : Lambda(l) {}
248258
using Lambda::operator();
249259
friend Lambda;
250260
} d(lambda);
251-
d(); // expected-error {{must derive publicly from the lambda}}
261+
d();
262+
// since-cxx23-error@-1 {{invalid explicit object parameter type 'D' in lambda with capture; the type must derive publicly from the lambda}}
263+
// since-cxx23-note@#cwg2881-D {{declared private here}}
252264
}
253265

254266
template <typename L>
@@ -263,34 +275,40 @@ struct Indirect : T {
263275
};
264276

265277
template<typename T>
266-
struct Ambiguous : Indirect<T>, T { // expected-warning {{is inaccessible due to ambiguity}}
278+
struct Ambiguous : Indirect<T>, T {
279+
/* since-cxx23-warning-re@-1 {{direct base '(lambda at {{.+}})' is inaccessible due to ambiguity:
280+
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> Indirect<(lambda at {{.+}})> -> class (lambda at {{.+}})
281+
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/
282+
// since-cxx23-note-re@#cwg2881-f4 {{in instantiation of template class 'cwg2881::Ambiguous<(lambda at {{.+}})>' requested here}}
283+
// since-cxx34-note-re@#cwg2881-f4-call {{while substituting deduced template arguments into function template 'f4' [with L = (lambda at {{.+}})]}}
267284
using Indirect<T>::operator();
268285
};
269286

270287
template <typename L>
271-
constexpr auto f3(L l) -> decltype(Private<L>{l}()) { return l(); }
272-
// expected-note@-1 {{must derive publicly from the lambda}}
288+
constexpr auto f3(L l) -> decltype(Private<L>{l}()) { return l(); } // #cwg2881-f3
273289

274290
template <typename L>
275-
constexpr auto f4(L l) -> decltype(Ambiguous<L>{{l}, l}()) { return l(); }
276-
// expected-note@-1 {{is inaccessible due to ambiguity}}
277-
// expected-note@-2 {{in instantiation of template class}}
291+
constexpr auto f4(L l) -> decltype(Ambiguous<L>{{l}, l}()) { return l(); } // #cwg2881-f4
278292

279293
template<typename T>
280294
concept is_callable = requires(T t) { { t() }; };
281295

282296
void g() {
283297
int x = 0;
284298
auto lambda = [x](this auto self) {};
285-
f3(lambda); // expected-error {{no matching function for call to 'f3'}}
286-
f4(lambda); // expected-error {{no matching function for call to 'f4'}}
287-
// expected-note@-1 {{while substituting deduced template arguments into function template 'f4'}}
299+
f3(lambda);
300+
// since-cxx23-error@-1 {{no matching function for call to 'f3'}}
301+
// since-cxx23-note-re@#cwg2881-f3 {{candidate template ignored: substitution failure [with L = (lambda at {{.+}})]: invalid explicit object parameter type 'cwg2881::Private<(lambda at {{.+}})>' in lambda with capture; the type must derive publicly from the lambda}}
302+
f4(lambda); // #cwg2881-f4-call
303+
// expected-error@-1 {{no matching function for call to 'f4'}}
304+
// expected-note-re@-2 {{while substituting deduced template arguments into function template 'f4' [with L = (lambda at {{.+}})]}}
305+
/* expected-note-re@#cwg2881-f4 {{candidate template ignored: substitution failure [with L = (lambda at {{.+}})]: lambda '(lambda at {{.+}})' is inaccessible due to ambiguity:
306+
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> Indirect<(lambda at {{.+}})> -> class (lambda at {{.+}})
307+
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/
288308
static_assert(!is_callable<Private<decltype(lambda)>>);
289309
static_assert(!is_callable<Ambiguous<decltype(lambda)>>);
290310
}
291-
292311
#endif
293-
294312
} // namespace cwg2881
295313

296314
namespace cwg2882 { // cwg2882: 2.7

0 commit comments

Comments
 (0)