| 1 |
// RUN: %clang_cc1 -std=c++20 -Wno-c++26-extensions -verify %s |
| 2 |
// RUN: %clang_cc1 -std=c++2c -Wno-c++26-extensions -verify %s |
| 3 |
|
| 4 |
|
| 5 |
static constexpr int PRIMARY = 0; |
| 6 |
static constexpr int SPECIALIZATION_CONCEPT = 1; |
| 7 |
static constexpr int SPECIALIZATION_REQUIRES = 2; |
| 8 |
|
| 9 |
template <class T> |
| 10 |
concept Concept = (sizeof(T) >= 2 * sizeof(int)); |
| 11 |
|
| 12 |
struct XY { |
| 13 |
int x; |
| 14 |
int y; |
| 15 |
}; |
| 16 |
|
| 17 |
namespace members { |
| 18 |
|
| 19 |
template <class T, class U> struct S { |
| 20 |
static constexpr int primary(); |
| 21 |
}; |
| 22 |
|
| 23 |
template <class T, class U> constexpr int S<T, U>::primary() { |
| 24 |
return PRIMARY; |
| 25 |
}; |
| 26 |
|
| 27 |
template <Concept C, class U> struct S<C, U> { |
| 28 |
static constexpr int specialization(); |
| 29 |
}; |
| 30 |
|
| 31 |
template <class T, class U> |
| 32 |
requires(sizeof(T) == sizeof(int)) |
| 33 |
struct S<T, U> { |
| 34 |
static constexpr int specialization(); |
| 35 |
}; |
| 36 |
|
| 37 |
template <Concept C, class U> constexpr int S<C, U>::specialization() { |
| 38 |
return SPECIALIZATION_CONCEPT; |
| 39 |
} |
| 40 |
|
| 41 |
template <class T, class U> |
| 42 |
requires(sizeof(T) == sizeof(int)) |
| 43 |
constexpr int S<T, U>::specialization() { |
| 44 |
return SPECIALIZATION_REQUIRES; |
| 45 |
} |
| 46 |
|
| 47 |
static_assert(S<char, double>::primary() == PRIMARY); |
| 48 |
static_assert(S<XY, double>::specialization() == SPECIALIZATION_CONCEPT); |
| 49 |
static_assert(S<int, double>::specialization() == SPECIALIZATION_REQUIRES); |
| 50 |
|
| 51 |
} // namespace members |
| 52 |
|
| 53 |
namespace enumerations { |
| 54 |
|
| 55 |
template <class T, class U> struct S { |
| 56 |
enum class E : int; |
| 57 |
}; |
| 58 |
|
| 59 |
template <class T, class U> enum class S<T, U>::E { Value = PRIMARY }; |
| 60 |
|
| 61 |
template <Concept C, class U> struct S<C, U> { |
| 62 |
enum class E : int; |
| 63 |
}; |
| 64 |
|
| 65 |
template <Concept C, class U> |
| 66 |
enum class S<C, U>::E { |
| 67 |
Value = SPECIALIZATION_CONCEPT |
| 68 |
}; |
| 69 |
|
| 70 |
template <class T, class U> |
| 71 |
requires(sizeof(T) == sizeof(int)) |
| 72 |
struct S<T, U> { |
| 73 |
enum class E : int; |
| 74 |
}; |
| 75 |
|
| 76 |
template <class T, class U> |
| 77 |
requires(sizeof(T) == sizeof(int)) |
| 78 |
enum class S<T, U>::E { |
| 79 |
Value = SPECIALIZATION_REQUIRES |
| 80 |
}; |
| 81 |
|
| 82 |
static_assert(static_cast<int>(S<char, double>::E::Value) == PRIMARY); |
| 83 |
static_assert(static_cast<int>(S<XY, double>::E::Value) == |
| 84 |
SPECIALIZATION_CONCEPT); |
| 85 |
static_assert(static_cast<int>(S<int, double>::E::Value) == |
| 86 |
SPECIALIZATION_REQUIRES); |
| 87 |
|
| 88 |
} // namespace enumerations |
| 89 |
|
| 90 |
namespace multiple_template_parameter_lists { |
| 91 |
|
| 92 |
template <class Outer> |
| 93 |
struct S { |
| 94 |
template <class Inner> |
| 95 |
static constexpr int primary(Inner); |
| 96 |
}; |
| 97 |
|
| 98 |
template <class Outer> |
| 99 |
template <class Inner> |
| 100 |
constexpr int S<Outer>::primary(Inner) { |
| 101 |
return PRIMARY; |
| 102 |
}; |
| 103 |
|
| 104 |
template <Concept Outer> |
| 105 |
struct S<Outer> { |
| 106 |
template <class Inner> |
| 107 |
static constexpr int specialization(Inner); |
| 108 |
}; |
| 109 |
|
| 110 |
template <Concept Outer> |
| 111 |
template <class Inner> |
| 112 |
constexpr int S<Outer>::specialization(Inner) { return SPECIALIZATION_CONCEPT; } |
| 113 |
|
| 114 |
template <class Outer> |
| 115 |
requires(sizeof(Outer) == sizeof(int)) |
| 116 |
struct S<Outer> { |
| 117 |
template <class Inner> |
| 118 |
static constexpr int specialization(Inner); |
| 119 |
}; |
| 120 |
|
| 121 |
template <class Outer> |
| 122 |
requires(sizeof(Outer) == sizeof(int)) |
| 123 |
template <class Inner> |
| 124 |
constexpr int S<Outer>::specialization(Inner) { return SPECIALIZATION_REQUIRES; } |
| 125 |
|
| 126 |
static_assert(S<char>::primary("str") == PRIMARY); |
| 127 |
static_assert(S<XY>::specialization("str") == SPECIALIZATION_CONCEPT); |
| 128 |
static_assert(S<int>::specialization("str") == SPECIALIZATION_REQUIRES); |
| 129 |
|
| 130 |
} // namespace multiple_template_parameter_lists |
| 131 |
|
| 132 |
static constexpr int CONSTRAINED_METHOD_1 = 1; |
| 133 |
static constexpr int CONSTRAINED_METHOD_2 = 2; |
| 134 |
|
| 135 |
namespace constrained_members { |
| 136 |
|
| 137 |
template <int> |
| 138 |
struct S { |
| 139 |
template <Concept C> |
| 140 |
static constexpr int constrained_method(); |
| 141 |
}; |
| 142 |
|
| 143 |
template <> |
| 144 |
template <Concept C> |
| 145 |
constexpr int S<1>::constrained_method() { return CONSTRAINED_METHOD_1; } |
| 146 |
|
| 147 |
template <> |
| 148 |
template <Concept C> |
| 149 |
constexpr int S<2>::constrained_method() { return CONSTRAINED_METHOD_2; } |
| 150 |
|
| 151 |
static_assert(S<1>::constrained_method<XY>() == CONSTRAINED_METHOD_1); |
| 152 |
static_assert(S<2>::constrained_method<XY>() == CONSTRAINED_METHOD_2); |
| 153 |
|
| 154 |
|
| 155 |
template <class T1, class T2> |
| 156 |
concept ConceptT1T2 = true; |
| 157 |
|
| 158 |
template<typename T3> |
| 159 |
struct S12 { |
| 160 |
template<ConceptT1T2<T3> T4> |
| 161 |
static constexpr int constrained_method(); |
| 162 |
}; |
| 163 |
|
| 164 |
template<> |
| 165 |
template<ConceptT1T2<int> T5> |
| 166 |
constexpr int S12<int>::constrained_method() { return CONSTRAINED_METHOD_1; } |
| 167 |
|
| 168 |
template<> |
| 169 |
template<ConceptT1T2<double> T5> |
| 170 |
constexpr int S12<double>::constrained_method() { return CONSTRAINED_METHOD_2; } |
| 171 |
|
| 172 |
static_assert(S12<int>::constrained_method<XY>() == CONSTRAINED_METHOD_1); |
| 173 |
static_assert(S12<double>::constrained_method<XY>() == CONSTRAINED_METHOD_2); |
| 174 |
|
| 175 |
} // namespace constrained members |
| 176 |
|
| 177 |
namespace constrained_members_of_nested_types { |
| 178 |
|
| 179 |
template <int> |
| 180 |
struct S { |
| 181 |
struct Inner0 { |
| 182 |
struct Inner1 { |
| 183 |
template <Concept C> |
| 184 |
static constexpr int constrained_method(); |
| 185 |
}; |
| 186 |
}; |
| 187 |
}; |
| 188 |
|
| 189 |
template <> |
| 190 |
template <Concept C> |
| 191 |
constexpr int S<1>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; } |
| 192 |
|
| 193 |
template <> |
| 194 |
template <Concept C> |
| 195 |
constexpr int S<2>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; } |
| 196 |
|
| 197 |
static_assert(S<1>::Inner0::Inner1::constrained_method<XY>() == CONSTRAINED_METHOD_1); |
| 198 |
static_assert(S<2>::Inner0::Inner1::constrained_method<XY>() == CONSTRAINED_METHOD_2); |
| 199 |
|
| 200 |
|
| 201 |
template <class T1, class T2> |
| 202 |
concept ConceptT1T2 = true; |
| 203 |
|
| 204 |
template<typename T3> |
| 205 |
struct S12 { |
| 206 |
struct Inner0 { |
| 207 |
struct Inner1 { |
| 208 |
template<ConceptT1T2<T3> T4> |
| 209 |
static constexpr int constrained_method(); |
| 210 |
}; |
| 211 |
}; |
| 212 |
}; |
| 213 |
|
| 214 |
template<> |
| 215 |
template<ConceptT1T2<int> T5> |
| 216 |
constexpr int S12<int>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_1; } |
| 217 |
|
| 218 |
template<> |
| 219 |
template<ConceptT1T2<double> T5> |
| 220 |
constexpr int S12<double>::Inner0::Inner1::constrained_method() { return CONSTRAINED_METHOD_2; } |
| 221 |
|
| 222 |
static_assert(S12<int>::Inner0::Inner1::constrained_method<XY>() == CONSTRAINED_METHOD_1); |
| 223 |
static_assert(S12<double>::Inner0::Inner1::constrained_method<XY>() == CONSTRAINED_METHOD_2); |
| 224 |
|
| 225 |
} // namespace constrained_members_of_nested_types |
| 226 |
|
| 227 |
namespace constrained_member_sfinae { |
| 228 |
|
| 229 |
template<int N> struct S { |
| 230 |
template<class T> |
| 231 |
static constexpr int constrained_method() requires (sizeof(int[N * 1073741824 + 4]) == 16) { // expected-warning {{variable length arrays in C++ are a Clang extension}} \ |
| 232 |
expected-note {{value 4294967296 is outside the range of representable values of type 'int'}} \ |
| 233 |
expected-note {{while calculating associated constraint of template 'constrained_method' here}} |
| 234 |
return CONSTRAINED_METHOD_1; |
| 235 |
} |
| 236 |
|
| 237 |
template<class T> |
| 238 |
static constexpr int constrained_method() requires (sizeof(int[N]) == 16); |
| 239 |
}; |
| 240 |
|
| 241 |
template<> |
| 242 |
template<typename T> |
| 243 |
constexpr int S<4>::constrained_method() requires (sizeof(int[4]) == 16) { |
| 244 |
return CONSTRAINED_METHOD_2; |
| 245 |
} |
| 246 |
|
| 247 |
// Verify that there is no amiguity in this case. |
| 248 |
static_assert(S<4>::constrained_method<double>() == CONSTRAINED_METHOD_2); |
| 249 |
|
| 250 |
} // namespace constrained_member_sfinae |
| 251 |
|
| 252 |
namespace requires_expression_references_members { |
| 253 |
|
| 254 |
void accept1(int x); |
| 255 |
void accept2(XY xy); |
| 256 |
|
| 257 |
template <class T> struct S { |
| 258 |
T Field = T(); |
| 259 |
|
| 260 |
constexpr int constrained_method() |
| 261 |
requires requires { accept1(Field); }; |
| 262 |
|
| 263 |
constexpr int constrained_method() |
| 264 |
requires requires { accept2(Field); }; |
| 265 |
}; |
| 266 |
|
| 267 |
template <class T> |
| 268 |
constexpr int S<T>::constrained_method() |
| 269 |
requires requires { accept1(Field); } { |
| 270 |
return CONSTRAINED_METHOD_1; |
| 271 |
} |
| 272 |
|
| 273 |
template <class T> |
| 274 |
constexpr int S<T>::constrained_method() |
| 275 |
requires requires { accept2(Field); } { |
| 276 |
return CONSTRAINED_METHOD_2; |
| 277 |
} |
| 278 |
|
| 279 |
static_assert(S<int>().constrained_method() == CONSTRAINED_METHOD_1); |
| 280 |
static_assert(S<XY>().constrained_method() == CONSTRAINED_METHOD_2); |
| 281 |
|
| 282 |
} // namespace requires_expression_references_members |
| 283 |
|
| 284 |
namespace GH60231 { |
| 285 |
|
| 286 |
template<typename T0> concept C = true; |
| 287 |
|
| 288 |
template <typename T1> |
| 289 |
struct S { |
| 290 |
template <typename F1> requires C<S<T1>> |
| 291 |
void foo1(F1 f); |
| 292 |
|
| 293 |
template <typename F2> |
| 294 |
void foo2(F2 f) requires C<S<T1>>; |
| 295 |
|
| 296 |
template <typename F3> requires C<F3> |
| 297 |
void foo3(F3 f); |
| 298 |
}; |
| 299 |
|
| 300 |
template <typename T2> |
| 301 |
template <typename F4> requires C<S<T2>> |
| 302 |
void S<T2>::foo1(F4 f) {} |
| 303 |
|
| 304 |
template <typename T3> |
| 305 |
template <typename F5> |
| 306 |
void S<T3>::foo2(F5 f) requires C<S<T3>> {} |
| 307 |
|
| 308 |
template <typename T4> |
| 309 |
template <typename F6> requires C<F6> |
| 310 |
void S<T4>::foo3(F6 f) {} |
| 311 |
|
| 312 |
} // namespace GH60231 |
| 313 |
|
| 314 |
namespace GH62003 { |
| 315 |
|
| 316 |
template <typename T0> concept Concept = true; |
| 317 |
|
| 318 |
template <class T1> |
| 319 |
struct S1 { |
| 320 |
template <Concept C1> |
| 321 |
static constexpr int foo(); |
| 322 |
}; |
| 323 |
template <class T2> |
| 324 |
template <Concept C2> |
| 325 |
constexpr int S1<T2>::foo() { return 1; } |
| 326 |
|
| 327 |
template <Concept C3> |
| 328 |
struct S2 { |
| 329 |
template <class T3> |
| 330 |
static constexpr int foo(); |
| 331 |
}; |
| 332 |
template <Concept C4> |
| 333 |
template <class T4> |
| 334 |
constexpr int S2<C4>::foo() { return 2; } |
| 335 |
|
| 336 |
template <Concept C5> |
| 337 |
struct S3 { |
| 338 |
template <Concept C6> |
| 339 |
static constexpr int foo(); |
| 340 |
}; |
| 341 |
template <Concept C7> |
| 342 |
template <Concept C8> |
| 343 |
constexpr int S3<C7>::foo() { return 3; } |
| 344 |
|
| 345 |
static_assert(S1<int>::foo<int>() == 1); |
| 346 |
static_assert(S2<int>::foo<int>() == 2); |
| 347 |
static_assert(S3<int>::foo<int>() == 3); |
| 348 |
|
| 349 |
} // namespace GH62003 |
| 350 |
|
| 351 |
namespace MultilevelTemplateWithPartialSpecialization { |
| 352 |
template <typename> |
| 353 |
concept Concept = true; |
| 354 |
|
| 355 |
namespace two_level { |
| 356 |
template <typename T1, int> |
| 357 |
struct W0 { |
| 358 |
template <typename T2> |
| 359 |
requires (Concept<T2>) |
| 360 |
void f(const T2 &); |
| 361 |
}; |
| 362 |
|
| 363 |
template <typename T3> |
| 364 |
struct W0<T3, 0> { |
| 365 |
template <typename T4> |
| 366 |
requires (Concept<T4>) |
| 367 |
void f(const T4 &); |
| 368 |
}; |
| 369 |
|
| 370 |
template <typename T3> |
| 371 |
template <typename T4> |
| 372 |
requires (Concept<T4>) |
| 373 |
inline void W0<T3, 0>::f(const T4 &) {} |
| 374 |
} // namespace two_level |
| 375 |
|
| 376 |
namespace three_level { |
| 377 |
template <typename T1, int> |
| 378 |
struct W0 { |
| 379 |
template <typename T2> |
| 380 |
struct W1 { |
| 381 |
template <typename T3> |
| 382 |
requires (Concept<T3>) |
| 383 |
void f(const T3 &); |
| 384 |
}; |
| 385 |
}; |
| 386 |
|
| 387 |
template <typename T4> |
| 388 |
struct W0<T4, 0> { |
| 389 |
template <typename T5> |
| 390 |
struct W1 { |
| 391 |
template <typename T6> |
| 392 |
requires (Concept<T6>) |
| 393 |
void f(const T6 &); |
| 394 |
}; |
| 395 |
}; |
| 396 |
|
| 397 |
template <typename T7> |
| 398 |
template <typename T8> |
| 399 |
template <typename T9> |
| 400 |
requires (Concept<T9>) |
| 401 |
inline void W0<T7, 0>::W1<T8>::f(const T9 &) {} |
| 402 |
} // namespace three_level |
| 403 |
|
| 404 |
} // namespace MultilevelTemplateWithPartialSpecialization |
| 405 |
|
| 406 |
namespace PR62697 { |
| 407 |
template<typename> |
| 408 |
concept c = true; |
| 409 |
|
| 410 |
template<typename T> |
| 411 |
struct s { |
| 412 |
void f() requires c<void(T)>; |
| 413 |
}; |
| 414 |
|
| 415 |
template<typename T> |
| 416 |
void s<T>::f() requires c<void(T)> { } |
| 417 |
} |
| 418 |
|
| 419 |
namespace GH62272 { |
| 420 |
template<typename T> concept A = true; |
| 421 |
template<typename T> struct X { A<T> auto f(); }; |
| 422 |
template<typename T> A<T> auto X<T>::f() {} |
| 423 |
} |
| 424 |
|
| 425 |
namespace GH65810 { |
| 426 |
template<typename Param> |
| 427 |
concept TrivialConcept = |
| 428 |
requires(Param param) { |
| 429 |
(void)param; |
| 430 |
}; |
| 431 |
|
| 432 |
template <typename T> |
| 433 |
struct Base { |
| 434 |
class InnerClass; |
| 435 |
}; |
| 436 |
|
| 437 |
template <typename T> |
| 438 |
class Base<T>::InnerClass { |
| 439 |
template <typename Param> |
| 440 |
requires TrivialConcept<Param> |
| 441 |
int func(Param param) const; |
| 442 |
}; |
| 443 |
|
| 444 |
template <typename T> |
| 445 |
template <typename Param> |
| 446 |
requires TrivialConcept<Param> |
| 447 |
int Base<T>::InnerClass::func(Param param) const { |
| 448 |
return 0; |
| 449 |
} |
| 450 |
|
| 451 |
template<typename T> |
| 452 |
struct Outermost { |
| 453 |
struct Middle { |
| 454 |
template<typename U> |
| 455 |
struct Innermost { |
| 456 |
template <typename Param> |
| 457 |
requires TrivialConcept<Param> |
| 458 |
int func(Param param) const; |
| 459 |
}; |
| 460 |
}; |
| 461 |
}; |
| 462 |
|
| 463 |
template <typename T> |
| 464 |
template <typename U> |
| 465 |
template <typename Param> |
| 466 |
requires TrivialConcept<Param> |
| 467 |
int Outermost<T>::Middle::Innermost<U>::func(Param param) const { |
| 468 |
return 0; |
| 469 |
} |
| 470 |
|
| 471 |
} // namespace GH65810 |
| 472 |
|
| 473 |
namespace GH61763 { |
| 474 |
template<typename T, typename U> |
| 475 |
concept same_as = true; |
| 476 |
|
| 477 |
template <class = void> |
| 478 |
struct Foo { |
| 479 |
template <same_as<void> Param> |
| 480 |
friend struct Bar; |
| 481 |
}; |
| 482 |
|
| 483 |
template struct Foo<>; |
| 484 |
|
| 485 |
template <same_as<void> Param> |
| 486 |
struct Bar { |
| 487 |
}; |
| 488 |
|
| 489 |
|
| 490 |
template<typename T> |
| 491 |
concept ok = true; |
| 492 |
|
| 493 |
struct outer { |
| 494 |
template<typename T> |
| 495 |
requires ok<T> |
| 496 |
struct foo {}; |
| 497 |
}; |
| 498 |
|
| 499 |
template<typename U> |
| 500 |
struct bar { |
| 501 |
template<typename T> |
| 502 |
requires ok<T> |
| 503 |
friend struct outer::foo; |
| 504 |
}; |
| 505 |
|
| 506 |
bar<int> x; |
| 507 |
} // namespace GH61763 |
| 508 |
|
| 509 |
|
| 510 |
namespace GH74314 { |
| 511 |
template <class T, class U> constexpr bool is_same_v = __is_same(T, U); |
| 512 |
template <class T, class U> constexpr bool is_not_same_v = !__is_same(T, U); |
| 513 |
|
| 514 |
template <class Result> |
| 515 |
concept something_interesting = requires { |
| 516 |
true; |
| 517 |
requires is_same_v<int, Result>; |
| 518 |
}; |
| 519 |
|
| 520 |
template <class T> |
| 521 |
struct X { // #defined-here |
| 522 |
void foo() requires requires { requires is_not_same_v<T, int>; }; |
| 523 |
void bar(decltype(requires { requires is_not_same_v<T, int>; })); |
| 524 |
}; |
| 525 |
|
| 526 |
template <class T> |
| 527 |
void X<T>::foo() requires requires { requires something_interesting<T>; } {} |
| 528 |
// expected-error@-1{{definition of 'foo' does not match any declaration}} |
| 529 |
// expected-note@#defined-here{{defined here}} |
| 530 |
// expected-note@-8{{member declaration nearly matches}} |
| 531 |
|
| 532 |
template <class T> |
| 533 |
void X<T>::foo() requires requires { requires is_not_same_v<T, int>; } {} // ok |
| 534 |
|
| 535 |
template <class T> |
| 536 |
void X<T>::bar(decltype(requires { requires something_interesting<T>; })) {} |
| 537 |
// expected-error@-1{{definition of 'bar' does not match any declaration}} |
| 538 |
// expected-note@#defined-here{{defined here}} |
| 539 |
|
| 540 |
template <class T> |
| 541 |
void X<T>::bar(decltype(requires { requires is_not_same_v<T, int>; })) {} |
| 542 |
} // namespace GH74314 |
| 543 |
|
| 544 |
namespace GH56482 { |
| 545 |
template <typename SlotMap> |
| 546 |
concept slot_map_has_reserve = true; |
| 547 |
|
| 548 |
template <typename T> struct Slot_map { |
| 549 |
constexpr void reserve() const noexcept |
| 550 |
requires slot_map_has_reserve<Slot_map>; |
| 551 |
|
| 552 |
constexpr void reserve(int) const noexcept |
| 553 |
requires slot_map_has_reserve<Slot_map<T>>; |
| 554 |
}; |
| 555 |
|
| 556 |
template <typename T> |
| 557 |
constexpr void Slot_map<T>::reserve() const noexcept |
| 558 |
requires slot_map_has_reserve<Slot_map<T>> |
| 559 |
{} |
| 560 |
|
| 561 |
template <typename T> |
| 562 |
constexpr void Slot_map<T>::reserve(int) const noexcept |
| 563 |
requires slot_map_has_reserve<Slot_map> |
| 564 |
{} |
| 565 |
} // namespace GH56482 |
| 566 |
|
| 567 |
namespace GH74447 { |
| 568 |
template <typename T> struct S { |
| 569 |
template <typename... U, int V> |
| 570 |
void test(T target, U... value) |
| 571 |
requires requires { |
| 572 |
target; |
| 573 |
sizeof...(value) == 1; |
| 574 |
V == 2; |
| 575 |
}; |
| 576 |
}; |
| 577 |
|
| 578 |
template <typename T> |
| 579 |
template <typename... U, int V> |
| 580 |
void S<T>::test(T target, U... value) |
| 581 |
requires requires { |
| 582 |
target; |
| 583 |
sizeof...(value) == 1; |
| 584 |
V == 2; |
| 585 |
} |
| 586 |
{} |
| 587 |
} // namespace GH74447 |
| 588 |
|
| 589 |
namespace GH72557 { |
| 590 |
|
| 591 |
template <typename...> |
| 592 |
concept IsAnyOf = true; |
| 593 |
|
| 594 |
template <class... DerTs> struct DerivedCollection { |
| 595 |
template <class DerT> |
| 596 |
requires IsAnyOf<DerTs...> |
| 597 |
unsigned long index(); |
| 598 |
}; |
| 599 |
|
| 600 |
template <class... DerTs> |
| 601 |
template <class DerT> |
| 602 |
requires IsAnyOf<DerTs...> |
| 603 |
unsigned long DerivedCollection<DerTs...>::index() {} |
| 604 |
|
| 605 |
} // namespace GH72557 |
| 606 |
|
| 607 |
namespace GH101735 { |
| 608 |
|
| 609 |
template <class, class> |
| 610 |
concept True = true; |
| 611 |
|
| 612 |
template <typename T> |
| 613 |
class A { |
| 614 |
template <typename... Ts> |
| 615 |
void method(Ts&... ts) |
| 616 |
requires requires (T t) { |
| 617 |
{ t.method(static_cast<Ts &&>(ts)...) } -> True<void>; |
| 618 |
}; |
| 619 |
}; |
| 620 |
|
| 621 |
template <typename T> |
| 622 |
template <typename... Ts> |
| 623 |
void A<T>::method(Ts&... ts) |
| 624 |
requires requires (T t) { |
| 625 |
{ t.method(static_cast<Ts &&>(ts)...) } -> True<void>; |
| 626 |
} {} |
| 627 |
|
| 628 |
} |
| 629 |
|
| 630 |
namespace GH63782 { |
| 631 |
// GH63782 was also fixed by PR #80594, so let's add a test for it. |
| 632 |
|
| 633 |
template<bool... Vals> |
| 634 |
constexpr bool All = (Vals && ...); |
| 635 |
|
| 636 |
template<bool... Bs> |
| 637 |
class Class { |
| 638 |
template<typename> |
| 639 |
requires All<Bs...> |
| 640 |
void Foo(); |
| 641 |
}; |
| 642 |
|
| 643 |
template<bool... Bs> |
| 644 |
template<typename> |
| 645 |
requires All<Bs...> |
| 646 |
void Class<Bs...>::Foo() { |
| 647 |
}; |
| 648 |
|
| 649 |
} // namespace GH63782 |
| 650 |
|
| 651 |
namespace eve { |
| 652 |
// Reduced from the "eve" project |
| 653 |
|
| 654 |
template <typename... Ts> |
| 655 |
struct tuple { |
| 656 |
template <int I0> requires(I0 <= sizeof...(Ts)) |
| 657 |
constexpr auto split(); |
| 658 |
}; |
| 659 |
|
| 660 |
template <typename... Ts> |
| 661 |
template <int I0> |
| 662 |
requires(I0 <= sizeof...(Ts)) |
| 663 |
constexpr auto tuple<Ts...>::split(){ |
| 664 |
return 0; |
| 665 |
} |
| 666 |
|
| 667 |
int foo() { |
| 668 |
tuple<int, float> x; |
| 669 |
return x.split<0>(); |
| 670 |
} |
| 671 |
|
| 672 |
} // namespace eve |
| 673 |
|
| 674 |
namespace GH93099 { |
| 675 |
|
| 676 |
// Issues with sizeof...(expr) |
| 677 |
|
| 678 |
template <typename T = int> struct C { |
| 679 |
template <int... N> |
| 680 |
requires(sizeof...(N) > 0) |
| 681 |
friend class NTTP; |
| 682 |
|
| 683 |
template <class... Tp> |
| 684 |
requires(sizeof...(Tp) > 0) |
| 685 |
friend class TP; |
| 686 |
|
| 687 |
template <template <typename> class... TTp> |
| 688 |
requires(sizeof...(TTp) > 0) |
| 689 |
friend class TTP; |
| 690 |
}; |
| 691 |
|
| 692 |
template <int... N> |
| 693 |
requires(sizeof...(N) > 0) |
| 694 |
class NTTP; |
| 695 |
|
| 696 |
template <class... Tp> |
| 697 |
requires(sizeof...(Tp) > 0) |
| 698 |
class TP; |
| 699 |
|
| 700 |
template <template <typename> class... TTp> |
| 701 |
requires(sizeof...(TTp) > 0) |
| 702 |
class TTP; |
| 703 |
|
| 704 |
C v; |
| 705 |
|
| 706 |
} // namespace GH93099 |
| 707 |
|
| 708 |
namespace GH115098 { |
| 709 |
|
| 710 |
template <typename... Ts> struct c { |
| 711 |
template <typename T> |
| 712 |
requires(sizeof...(Ts) > 0) |
| 713 |
friend bool operator==(c, c); |
| 714 |
}; |
| 715 |
|
| 716 |
template <typename... Ts> struct d { |
| 717 |
template <typename T> |
| 718 |
requires(sizeof...(Ts) > 0) |
| 719 |
friend bool operator==(d, d); |
| 720 |
}; |
| 721 |
|
| 722 |
template struct c<int>; |
| 723 |
template struct d<int, int>; |
| 724 |
|
| 725 |
} // namespace GH115098 |
| 726 |
|
| 727 |
namespace GH123441 { |
| 728 |
|
| 729 |
struct buf { |
| 730 |
constexpr buf(auto&&... initList) requires (sizeof...(initList) <= 8); |
| 731 |
}; |
| 732 |
|
| 733 |
constexpr buf::buf(auto&&... initList) requires (sizeof...(initList) <= 8) {} |
| 734 |
|
| 735 |
template <class> |
| 736 |
struct buffer { |
| 737 |
constexpr buffer(auto&&... initList) requires (sizeof...(initList) <= 8); |
| 738 |
}; |
| 739 |
|
| 740 |
template <class T> |
| 741 |
constexpr buffer<T>::buffer(auto&&... initList) requires (sizeof...(initList) <= 8) {} |
| 742 |
|
| 743 |
template <class...> |
| 744 |
struct foo { // expected-note {{foo defined here}} |
| 745 |
constexpr foo(auto&&... initList) |
| 746 |
requires (sizeof...(initList) <= 8); |
| 747 |
}; |
| 748 |
|
| 749 |
template <class... T> |
| 750 |
constexpr foo<T...>::foo(auto&&... initList) // expected-error {{does not match any declaration}} |
| 751 |
requires (sizeof...(T) <= 8) {} |
| 752 |
|
| 753 |
} // namespace GH123441 |
| 754 |
|
| 755 |
namespace GH114685 { |
| 756 |
|
| 757 |
template <typename T> struct ptr { |
| 758 |
template <typename U> |
| 759 |
friend ptr<U> make_item(auto &&args) |
| 760 |
requires(sizeof(args) > 1); |
| 761 |
}; |
| 762 |
|
| 763 |
template <typename U> |
| 764 |
ptr<U> make_item(auto &&args) |
| 765 |
requires(sizeof(args) > 1) {} |
| 766 |
|
| 767 |
ptr<char> p; |
| 768 |
|
| 769 |
} // namespace GH114685 |
| 770 |
|
| 771 |
namespace GH123472 { |
| 772 |
|
| 773 |
consteval bool fn() { return true; } |
| 774 |
|
| 775 |
struct S { |
| 776 |
template <typename T> |
| 777 |
static consteval void mfn() requires (bool(&fn)); |
| 778 |
}; |
| 779 |
|
| 780 |
template <typename T> |
| 781 |
consteval void S::mfn() requires (bool(&fn)) {} |
| 782 |
|
| 783 |
} |
| 784 |
|
| 785 |
|
| 786 |
namespace GH138255 { |
| 787 |
|
| 788 |
template <typename... T> |
| 789 |
concept C = true; |
| 790 |
|
| 791 |
struct Func { |
| 792 |
template<typename... Ts> |
| 793 |
requires C<Ts...[0]> |
| 794 |
static auto buggy() -> void; |
| 795 |
|
| 796 |
template<typename... Ts> |
| 797 |
requires C<Ts...[0]> |
| 798 |
friend auto fr() -> void; |
| 799 |
|
| 800 |
template<typename... Ts> |
| 801 |
requires C<Ts...[0]> |
| 802 |
friend auto fr2() -> void{}; // expected-note{{previous definition is here}} |
| 803 |
}; |
| 804 |
|
| 805 |
template<typename... Ts> |
| 806 |
requires C<Ts...[0]> |
| 807 |
auto Func::buggy() -> void {} |
| 808 |
|
| 809 |
template<typename... Ts> |
| 810 |
requires C<Ts...[0]> |
| 811 |
auto fr() -> void {} |
| 812 |
|
| 813 |
template<typename... Ts> |
| 814 |
requires C<Ts...[0]> |
| 815 |
auto fr2() -> void {} // expected-error{{redefinition of 'fr2'}} |
| 816 |
|
| 817 |
|
| 818 |
template <typename... Ts> |
| 819 |
requires C<Ts...[0]> |
| 820 |
struct Class; |
| 821 |
|
| 822 |
template <typename... Ts> |
| 823 |
requires C<Ts...[0]> |
| 824 |
struct Class; |
| 825 |
|
| 826 |
|
| 827 |
template <typename...> |
| 828 |
struct TplClass { |
| 829 |
template<typename... Ts> |
| 830 |
requires C<Ts...[0]> |
| 831 |
static auto buggy() -> void; |
| 832 |
}; |
| 833 |
|
| 834 |
template<> |
| 835 |
template<typename... Ts> |
| 836 |
requires C<Ts...[0]> |
| 837 |
auto TplClass<int>::buggy() -> void {} |
| 838 |
|
| 839 |
} |
| 840 |
|
| 841 |
namespace PackIndexExpr { |
| 842 |
template <int... T> |
| 843 |
concept C = true; |
| 844 |
|
| 845 |
template <typename...> struct TplClass { |
| 846 |
template <int... Ts> |
| 847 |
requires C<Ts...[0]> |
| 848 |
static auto buggy() -> void; |
| 849 |
}; |
| 850 |
|
| 851 |
template <> |
| 852 |
template <int... Ts> |
| 853 |
requires C<Ts...[0]> |
| 854 |
auto TplClass<int>::buggy() -> void {} |
| 855 |
} |
| 856 |
|
| 857 |
namespace GH139476 { |
| 858 |
|
| 859 |
namespace moo { |
| 860 |
template <typename T> |
| 861 |
constexpr bool baa = true; |
| 862 |
|
| 863 |
template <typename T> requires baa<T> |
| 864 |
void caw(); |
| 865 |
} |
| 866 |
|
| 867 |
template <typename T> requires moo::baa<T> |
| 868 |
void moo::caw() {} |
| 869 |
|
| 870 |
} |
| 871 |
|
| 872 |
namespace GH145521 { |
| 873 |
|
| 874 |
template <typename X> |
| 875 |
concept is_valid = true; |
| 876 |
|
| 877 |
template<typename T> |
| 878 |
class Nesting |
| 879 |
{ |
| 880 |
public: |
| 881 |
template<typename Q> requires is_valid<Q> |
| 882 |
class Inner; |
| 883 |
|
| 884 |
template<typename Q> requires is_valid<Q> |
| 885 |
friend class Inner2; |
| 886 |
}; |
| 887 |
|
| 888 |
template<typename T> |
| 889 |
template<typename Q> requires is_valid<Q> |
| 890 |
class Nesting<T>::Inner {}; |
| 891 |
|
| 892 |
template<typename Q> requires is_valid<Q> |
| 893 |
class Inner2 {}; |
| 894 |
|
| 895 |
} |