| 1 |
// RUN: %clang_cc1 -std=c++98 -pedantic-errors -verify=expected,cxx98 %s |
| 2 |
// RUN: %clang_cc1 -std=c++11 -pedantic-errors -verify=expected,since-cxx11,cxx11-23 %s |
| 3 |
// RUN: %clang_cc1 -std=c++14 -pedantic-errors -verify=expected,since-cxx11,cxx11-23 %s |
| 4 |
// RUN: %clang_cc1 -std=c++17 -pedantic-errors -verify=expected,since-cxx11,cxx11-23 %s |
| 5 |
// RUN: %clang_cc1 -std=c++20 -pedantic-errors -verify=expected,since-cxx11,cxx11-23,since-cxx20 %s |
| 6 |
// RUN: %clang_cc1 -std=c++23 -pedantic-errors -verify=expected,since-cxx11,cxx11-23,since-cxx20,since-cxx23 %s |
| 7 |
// RUN: %clang_cc1 -std=c++2c -pedantic-errors -verify=expected,since-cxx11,since-cxx20,since-cxx23,since-cxx26 %s |
| 8 |
|
| 9 |
|
| 10 |
int main() {} // required for cwg2811 |
| 11 |
|
| 12 |
namespace cwg2811 { // cwg2811: 3.5 |
| 13 |
#if __cplusplus >= 201103L |
| 14 |
void f() { |
| 15 |
(void)[&] { |
| 16 |
using T = decltype(main); |
| 17 |
// since-cxx11-error@-1 {{referring to 'main' within an expression is a Clang extension}} |
| 18 |
}; |
| 19 |
using T2 = decltype(main); |
| 20 |
// since-cxx11-error@-1 {{referring to 'main' within an expression is a Clang extension}} |
| 21 |
} |
| 22 |
|
| 23 |
using T = decltype(main); |
| 24 |
// since-cxx11-error@-1 {{referring to 'main' within an expression is a Clang extension}} |
| 25 |
|
| 26 |
int main(); |
| 27 |
|
| 28 |
using U = decltype(main); |
| 29 |
using U2 = decltype(&main); |
| 30 |
#endif |
| 31 |
} // namespace cwg2811 |
| 32 |
|
| 33 |
namespace cwg2813 { // cwg2813: 20 |
| 34 |
#if __cplusplus >= 202302L |
| 35 |
struct X { |
| 36 |
X() = default; |
| 37 |
|
| 38 |
X(const X&) = delete; |
| 39 |
X& operator=(const X&) = delete; |
| 40 |
|
| 41 |
void f(this X self) { } |
| 42 |
}; |
| 43 |
|
| 44 |
void f() { |
| 45 |
X{}.f(); |
| 46 |
} |
| 47 |
#endif |
| 48 |
} // namespace cwg2813 |
| 49 |
|
| 50 |
namespace cwg2819 { // cwg2819: 19 c++26 |
| 51 |
#if __cplusplus >= 201103L |
| 52 |
// CWG 2024-04-19: This issue is not a DR. |
| 53 |
constexpr void* p = nullptr; |
| 54 |
constexpr int* q = static_cast<int*>(p); // #cwg2819-q |
| 55 |
// cxx11-23-error@-1 {{constexpr variable 'q' must be initialized by a constant expression}} |
| 56 |
// cxx11-23-note@-2 {{cast from 'void *' is not allowed in a constant expression}} |
| 57 |
static_assert(q == nullptr, ""); |
| 58 |
// cxx11-23-error@-1 {{static assertion expression is not an integral constant expression}} |
| 59 |
// cxx11-23-note@-2 {{initializer of 'q' is not a constant expression}} |
| 60 |
// cxx11-23-note@#cwg2819-q {{declared here}} |
| 61 |
#endif |
| 62 |
} // namespace cwg2819 |
| 63 |
|
| 64 |
namespace cwg2823 { // cwg2823: no |
| 65 |
#if __cplusplus >= 201103L |
| 66 |
constexpr int *p = 0; |
| 67 |
constexpr int *q1 = &*p; |
| 68 |
// expected-error@-1 {{constexpr variable 'q1' must be initialized by a constant expression}} |
| 69 |
// expected-note@-2 {{dereferencing a null pointer is not allowed in a constant expression}} |
| 70 |
// FIXME: invalid: dereferencing a null pointer. |
| 71 |
constexpr int *q2 = &p[0]; |
| 72 |
|
| 73 |
int arr[32]; |
| 74 |
constexpr int *r = arr; |
| 75 |
// FIXME: invalid: dereferencing a past-the-end pointer. |
| 76 |
constexpr int *s1 = &*(r + 32); |
| 77 |
// FIXME: invalid: dereferencing a past-the-end pointer. |
| 78 |
constexpr int *s2 = &r[32]; |
| 79 |
#endif |
| 80 |
} |
| 81 |
|
| 82 |
namespace cwg2847 { // cwg2847: 19 review 2024-03-01 |
| 83 |
|
| 84 |
#if __cplusplus >= 202002L |
| 85 |
|
| 86 |
template<typename> |
| 87 |
void i(); |
| 88 |
|
| 89 |
struct A { |
| 90 |
template<typename> |
| 91 |
void f() requires true; |
| 92 |
|
| 93 |
template<> |
| 94 |
void f<int>() requires true; |
| 95 |
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} |
| 96 |
|
| 97 |
friend void i<int>() requires true; |
| 98 |
// since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}} |
| 99 |
}; |
| 100 |
|
| 101 |
template<typename> |
| 102 |
struct B { |
| 103 |
void f() requires true; |
| 104 |
|
| 105 |
template<typename> |
| 106 |
void g() requires true; |
| 107 |
|
| 108 |
template<typename> |
| 109 |
void h() requires true; |
| 110 |
|
| 111 |
template<> |
| 112 |
void h<int>() requires true; |
| 113 |
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} |
| 114 |
|
| 115 |
friend void i<int>() requires true; |
| 116 |
// since-cxx20-error@-1 {{friend specialization cannot have a trailing requires clause unless it declares a function template}} |
| 117 |
}; |
| 118 |
|
| 119 |
template<> |
| 120 |
void B<int>::f() requires true; |
| 121 |
// since-cxx20-error@-1 {{explicit specialization cannot have a trailing requires clause unless it declares a function template}} |
| 122 |
|
| 123 |
template<> |
| 124 |
template<typename T> |
| 125 |
void B<int>::g() requires true; |
| 126 |
|
| 127 |
#endif |
| 128 |
|
| 129 |
} // namespace cwg2847 |
| 130 |
|
| 131 |
namespace cwg2857 { // cwg2857: no |
| 132 |
struct A {}; |
| 133 |
template <typename> |
| 134 |
struct D; |
| 135 |
namespace N { |
| 136 |
struct B {}; |
| 137 |
void adl_only(A*, D<int>*); // #cwg2857-adl_only |
| 138 |
} |
| 139 |
|
| 140 |
void f(A* a, D<int>* d) { |
| 141 |
adl_only(a, d); |
| 142 |
// expected-error@-1 {{use of undeclared identifier 'adl_only'; did you mean 'N::adl_only'?}} |
| 143 |
// expected-note@#cwg2857-adl_only {{'N::adl_only' declared here}} |
| 144 |
} |
| 145 |
|
| 146 |
#if __cplusplus >= 201103L |
| 147 |
template <typename> |
| 148 |
struct D : N::B { |
| 149 |
// FIXME: ADL shouldn't associate it's base B and N since D is not complete here |
| 150 |
decltype(adl_only((A*) nullptr, (D*) nullptr)) f; |
| 151 |
}; |
| 152 |
#endif |
| 153 |
} // namespace cwg2857 |
| 154 |
|
| 155 |
namespace cwg2858 { // cwg2858: 19 |
| 156 |
|
| 157 |
#if __cplusplus > 202302L |
| 158 |
|
| 159 |
template<typename... Ts> |
| 160 |
struct A { |
| 161 |
// FIXME: The nested-name-specifier in the following friend declarations are declarative, |
| 162 |
// but we don't treat them as such (yet). |
| 163 |
friend void Ts...[0]::f(); |
| 164 |
template<typename U> |
| 165 |
friend void Ts...[0]::g(); |
| 166 |
|
| 167 |
friend struct Ts...[0]::B; |
| 168 |
// FIXME: The index of the pack-index-specifier is printed as a memory address in the diagnostic. |
| 169 |
template<typename U> |
| 170 |
friend struct Ts...[0]::C; |
| 171 |
// since-cxx26-warning@-1 {{dependent nested name specifier 'Ts...[0]' for friend template declaration is not supported; ignoring this friend declaration}} |
| 172 |
}; |
| 173 |
|
| 174 |
#endif |
| 175 |
|
| 176 |
} // namespace cwg2858 |
| 177 |
|
| 178 |
namespace cwg2877 { // cwg2877: 19 |
| 179 |
#if __cplusplus >= 202002L |
| 180 |
enum E { x }; |
| 181 |
void f() { |
| 182 |
int E; |
| 183 |
using enum E; // OK |
| 184 |
} |
| 185 |
using F = E; |
| 186 |
using enum F; // OK |
| 187 |
template<class T> using EE = T; |
| 188 |
void g() { |
| 189 |
using enum EE<E>; // OK |
| 190 |
} |
| 191 |
#endif |
| 192 |
} // namespace cwg2877 |
| 193 |
|
| 194 |
namespace cwg2881 { // cwg2881: 19 |
| 195 |
#if __cplusplus >= 202302L |
| 196 |
template <typename T> struct A : T {}; |
| 197 |
template <typename T> struct B : T {}; |
| 198 |
template <typename T> struct C : virtual T { C(T t) : T(t) {} }; |
| 199 |
template <typename T> struct D : virtual T { D(T t) : T(t) {} }; |
| 200 |
|
| 201 |
template <typename Ts> |
| 202 |
struct O1 : A<Ts>, B<Ts> { |
| 203 |
using A<Ts>::operator(); |
| 204 |
using B<Ts>::operator(); |
| 205 |
}; |
| 206 |
|
| 207 |
template <typename Ts> struct O2 : protected Ts { // #cwg2881-O2 |
| 208 |
using Ts::operator(); |
| 209 |
O2(Ts ts) : Ts(ts) {} |
| 210 |
}; |
| 211 |
|
| 212 |
template <typename Ts> struct O3 : private Ts { // #cwg2881-O3 |
| 213 |
using Ts::operator(); |
| 214 |
O3(Ts ts) : Ts(ts) {} |
| 215 |
}; |
| 216 |
|
| 217 |
// Not ambiguous because of virtual inheritance. |
| 218 |
template <typename Ts> |
| 219 |
struct O4 : C<Ts>, D<Ts> { |
| 220 |
using C<Ts>::operator(); |
| 221 |
using D<Ts>::operator(); |
| 222 |
O4(Ts t) : Ts(t), C<Ts>(t), D<Ts>(t) {} |
| 223 |
}; |
| 224 |
|
| 225 |
// This still has a public path to the lambda, and it's also not |
| 226 |
// ambiguous because of virtual inheritance. |
| 227 |
template <typename Ts> |
| 228 |
struct O5 : private C<Ts>, D<Ts> { |
| 229 |
using C<Ts>::operator(); |
| 230 |
using D<Ts>::operator(); |
| 231 |
O5(Ts t) : Ts(t), C<Ts>(t), D<Ts>(t) {} |
| 232 |
}; |
| 233 |
|
| 234 |
// This is only invalid if we call T's call operator. |
| 235 |
template <typename T, typename U> |
| 236 |
struct O6 : private T, U { // #cwg2881-O6 |
| 237 |
using T::operator(); |
| 238 |
using U::operator(); |
| 239 |
O6(T t, U u) : T(t), U(u) {} |
| 240 |
}; |
| 241 |
|
| 242 |
void f() { |
| 243 |
int x; |
| 244 |
auto L1 = [=](this auto&& self) { (void) &x; }; |
| 245 |
auto L2 = [&](this auto&& self) { (void) &x; }; |
| 246 |
O1<decltype(L1)>{L1, L1}(); |
| 247 |
/* since-cxx23-error-re@-1 {{inaccessible due to ambiguity: |
| 248 |
struct cwg2881::O1<class (lambda at {{.+}})> -> A<class (lambda at {{.+}})> -> class (lambda at {{.+}}) |
| 249 |
struct cwg2881::O1<class (lambda at {{.+}})> -> B<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/ |
| 250 |
O1<decltype(L2)>{L2, L2}(); |
| 251 |
/* since-cxx23-error-re@-1 {{inaccessible due to ambiguity: |
| 252 |
struct cwg2881::O1<class (lambda at {{.+}})> -> A<class (lambda at {{.+}})> -> class (lambda at {{.+}}) |
| 253 |
struct cwg2881::O1<class (lambda at {{.+}})> -> B<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/ |
| 254 |
O2{L1}(); |
| 255 |
// 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}} |
| 256 |
// since-cxx23-note@#cwg2881-O2 {{declared protected here}} |
| 257 |
O3{L1}(); |
| 258 |
// 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}} |
| 259 |
// since-cxx23-note@#cwg2881-O3 {{declared private here}} |
| 260 |
O4{L1}(); |
| 261 |
O5{L1}(); |
| 262 |
O6 o{L1, L2}; |
| 263 |
o.decltype(L1)::operator()(); |
| 264 |
// 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}} |
| 265 |
// since-cxx23-note@#cwg2881-O6 {{declared private here}} |
| 266 |
o.decltype(L1)::operator()(); // No error here because we've already diagnosed this method. |
| 267 |
o.decltype(L2)::operator()(); |
| 268 |
} |
| 269 |
|
| 270 |
void f2() { |
| 271 |
int x = 0; |
| 272 |
auto lambda = [x] (this auto self) { return x; }; |
| 273 |
using Lambda = decltype(lambda); |
| 274 |
struct D : private Lambda { // #cwg2881-D |
| 275 |
D(Lambda l) : Lambda(l) {} |
| 276 |
using Lambda::operator(); |
| 277 |
friend Lambda; |
| 278 |
} d(lambda); |
| 279 |
d(); |
| 280 |
// since-cxx23-error@-1 {{invalid explicit object parameter type 'D' in lambda with capture; the type must derive publicly from the lambda}} |
| 281 |
// since-cxx23-note@#cwg2881-D {{declared private here}} |
| 282 |
} |
| 283 |
|
| 284 |
template <typename L> |
| 285 |
struct Private : private L { |
| 286 |
using L::operator(); |
| 287 |
Private(L l) : L(l) {} |
| 288 |
}; |
| 289 |
|
| 290 |
template<typename T> |
| 291 |
struct Indirect : T { |
| 292 |
using T::operator(); |
| 293 |
}; |
| 294 |
|
| 295 |
template<typename T> |
| 296 |
struct Ambiguous : Indirect<T>, T { |
| 297 |
/* since-cxx23-warning-re@-1 {{direct base '(lambda at {{.+}})' is inaccessible due to ambiguity: |
| 298 |
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> Indirect<class (lambda at {{.+}})> -> class (lambda at {{.+}}) |
| 299 |
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/ |
| 300 |
// since-cxx23-note-re@#cwg2881-f4 {{in instantiation of template class 'cwg2881::Ambiguous<(lambda at {{.+}})>' requested here}} |
| 301 |
// since-cxx34-note-re@#cwg2881-f4-call {{while substituting deduced template arguments into function template 'f4' [with L = (lambda at {{.+}})]}} |
| 302 |
using Indirect<T>::operator(); |
| 303 |
}; |
| 304 |
|
| 305 |
template <typename L> |
| 306 |
constexpr auto f3(L l) -> decltype(Private<L>{l}()) { return l(); } // #cwg2881-f3 |
| 307 |
|
| 308 |
template <typename L> |
| 309 |
constexpr auto f4(L l) -> decltype(Ambiguous<L>{{l}, l}()) { return l(); } // #cwg2881-f4 |
| 310 |
|
| 311 |
template<typename T> |
| 312 |
concept is_callable = requires(T t) { { t() }; }; |
| 313 |
|
| 314 |
void g() { |
| 315 |
int x = 0; |
| 316 |
auto lambda = [x](this auto self) {}; |
| 317 |
f3(lambda); |
| 318 |
// since-cxx23-error@-1 {{no matching function for call to 'f3'}} |
| 319 |
// 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}} |
| 320 |
f4(lambda); // #cwg2881-f4-call |
| 321 |
// expected-error@-1 {{no matching function for call to 'f4'}} |
| 322 |
// expected-note-re@-2 {{while substituting deduced template arguments into function template 'f4' [with L = (lambda at {{.+}})]}} |
| 323 |
/* expected-note-re@#cwg2881-f4 {{candidate template ignored: substitution failure [with L = (lambda at {{.+}})]: lambda '(lambda at {{.+}})' is inaccessible due to ambiguity: |
| 324 |
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> Indirect<class (lambda at {{.+}})> -> class (lambda at {{.+}}) |
| 325 |
struct cwg2881::Ambiguous<class (lambda at {{.+}})> -> class (lambda at {{.+}})}}*/ |
| 326 |
static_assert(!is_callable<Private<decltype(lambda)>>); |
| 327 |
static_assert(!is_callable<Ambiguous<decltype(lambda)>>); |
| 328 |
} |
| 329 |
#endif |
| 330 |
} // namespace cwg2881 |
| 331 |
|
| 332 |
namespace cwg2882 { // cwg2882: 2.7 |
| 333 |
struct C { |
| 334 |
operator void() = delete; |
| 335 |
// expected-warning@-1 {{conversion function converting 'cwg2882::C' to 'void' will never be used}} |
| 336 |
// cxx98-error@-2 {{deleted function definitions are a C++11 extension}} |
| 337 |
}; |
| 338 |
|
| 339 |
void f(C c) { |
| 340 |
(void)c; |
| 341 |
} |
| 342 |
} // namespace cwg2882 |
| 343 |
|
| 344 |
namespace cwg2883 { // cwg2883: no |
| 345 |
#if __cplusplus >= 201103L |
| 346 |
void f() { |
| 347 |
int x; |
| 348 |
(void)[&] { |
| 349 |
return x; |
| 350 |
}; |
| 351 |
} |
| 352 |
#endif |
| 353 |
#if __cplusplus >= 202002L |
| 354 |
struct A { |
| 355 |
A() = default; |
| 356 |
A(const A &) = delete; // #cwg2883-A-copy-ctor |
| 357 |
constexpr operator int() { return 42; } |
| 358 |
}; |
| 359 |
void g() { |
| 360 |
constexpr A a; |
| 361 |
// FIXME: OK, not odr-usable from a default template argument, and not odr-used |
| 362 |
(void)[=]<typename T, int = a> {}; |
| 363 |
// since-cxx20-error@-1 {{call to deleted constructor of 'const A'}} |
| 364 |
// since-cxx20-note@#cwg2883-A-copy-ctor {{'A' has been explicitly marked deleted here}} |
| 365 |
} |
| 366 |
#endif |
| 367 |
} // namespace cwg2883 |
| 368 |
|
| 369 |
namespace cwg2885 { // cwg2885: 16 review 2024-05-31 |
| 370 |
#if __cplusplus >= 202002L |
| 371 |
template <class T> |
| 372 |
struct A { |
| 373 |
A() requires (false) = default; |
| 374 |
A() : t(42) {} |
| 375 |
T t; |
| 376 |
}; |
| 377 |
|
| 378 |
struct B : A<int> {}; |
| 379 |
static_assert(!__is_trivially_constructible(B)); |
| 380 |
#endif |
| 381 |
} // namespace cwg2885 |
| 382 |
|
| 383 |
namespace cwg2886 { // cwg2886: 9 |
| 384 |
#if __cplusplus >= 201103L |
| 385 |
struct C { |
| 386 |
C() = default; |
| 387 |
~C() noexcept(false) = default; |
| 388 |
}; |
| 389 |
|
| 390 |
static_assert(noexcept(C()), ""); |
| 391 |
#endif |
| 392 |
} // namespace cwg2886 |