| 1 |
// RUN: %clang_cc1 -std=c++20 -verify %s |
| 2 |
|
| 3 |
template<int I> |
| 4 |
concept C = I >= 4; |
| 5 |
|
| 6 |
template<int I> |
| 7 |
concept D = I < 8; |
| 8 |
|
| 9 |
template<int I> |
| 10 |
struct A { |
| 11 |
constexpr static int f() { return 0; } |
| 12 |
constexpr static int f() requires C<I> && D<I> { return 1; } |
| 13 |
constexpr static int f() requires C<I> { return 2; } |
| 14 |
|
| 15 |
constexpr static int g() requires C<I> { return 0; } // #candidate-0 |
| 16 |
constexpr static int g() requires D<I> { return 1; } // #candidate-1 |
| 17 |
|
| 18 |
constexpr static int h() requires C<I> { return 0; } // expected-note {{member declaration nearly matches}} |
| 19 |
}; |
| 20 |
|
| 21 |
template<> |
| 22 |
constexpr int A<2>::f() { return 3; } |
| 23 |
|
| 24 |
template<> |
| 25 |
constexpr int A<4>::f() { return 4; } |
| 26 |
|
| 27 |
template<> |
| 28 |
constexpr int A<8>::f() { return 5; } |
| 29 |
|
| 30 |
static_assert(A<3>::f() == 0); |
| 31 |
static_assert(A<5>::f() == 1); |
| 32 |
static_assert(A<9>::f() == 2); |
| 33 |
static_assert(A<2>::f() == 3); |
| 34 |
static_assert(A<4>::f() == 4); |
| 35 |
static_assert(A<8>::f() == 5); |
| 36 |
|
| 37 |
template<> |
| 38 |
constexpr int A<0>::g() { return 2; } |
| 39 |
|
| 40 |
template<> |
| 41 |
constexpr int A<8>::g() { return 3; } |
| 42 |
|
| 43 |
template<> |
| 44 |
constexpr int A<6>::g() { return 4; } // expected-error {{ambiguous member function specialization 'A<6>::g' of 'A::g'}} |
| 45 |
// expected-note@#candidate-0 {{member function specialization matches 'g'}} |
| 46 |
// expected-note@#candidate-1 {{member function specialization matches 'g'}} |
| 47 |
|
| 48 |
static_assert(A<9>::g() == 0); |
| 49 |
static_assert(A<1>::g() == 1); |
| 50 |
static_assert(A<0>::g() == 2); |
| 51 |
static_assert(A<8>::g() == 3); |
| 52 |
|
| 53 |
template<> |
| 54 |
constexpr int A<4>::h() { return 1; } |
| 55 |
|
| 56 |
template<> |
| 57 |
constexpr int A<0>::h() { return 2; } // expected-error {{out-of-line definition of 'h' does not match any declaration in 'A<0>'}} |
| 58 |
|
| 59 |
static_assert(A<5>::h() == 0); |
| 60 |
static_assert(A<4>::h() == 1); |