| 1 |
// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s |
| 2 |
|
| 3 |
template<typename T> requires (sizeof(T) >= 4) |
| 4 |
// expected-note@-1{{similar constraint expressions not considered equivalent}} |
| 5 |
bool a = false; // expected-note{{template is declared here}} |
| 6 |
|
| 7 |
template<typename T> requires (sizeof(T) >= 4 && sizeof(T) <= 10) |
| 8 |
// expected-note@-1{{similar constraint expression here}} |
| 9 |
bool a<T> = true; // expected-error{{variable template partial specialization is not more specialized than the primary template}} |
| 10 |
|
| 11 |
template<typename T> |
| 12 |
concept C1 = sizeof(T) >= 4; |
| 13 |
|
| 14 |
template<typename T> requires C1<T> |
| 15 |
bool b = false; |
| 16 |
|
| 17 |
template<typename T> requires (C1<T> && sizeof(T) <= 10) |
| 18 |
bool b<T> = true; |
| 19 |
|
| 20 |
template<typename T> |
| 21 |
concept C2 = sizeof(T) > 1 && sizeof(T) <= 8; |
| 22 |
|
| 23 |
template<typename T> |
| 24 |
bool c = false; |
| 25 |
|
| 26 |
template<typename T> requires C1<T> |
| 27 |
bool c<T> = true; |
| 28 |
|
| 29 |
template<typename T> |
| 30 |
bool d = false; |
| 31 |
|
| 32 |
template<typename T> |
| 33 |
bool d<T> = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}} |
| 34 |
|
| 35 |
template<typename T> requires C1<T> |
| 36 |
bool e = false; |
| 37 |
|
| 38 |
template<typename T> |
| 39 |
bool e<T> = true; // expected-error{{variable template partial specialization does not specialize any template argument; to define the primary template, remove the template argument list}} |
| 40 |
|
| 41 |
template<typename T> |
| 42 |
constexpr int f = 1; |
| 43 |
|
| 44 |
template<typename T> requires C1<T> && C2<T> |
| 45 |
constexpr int f<T> = 2; |
| 46 |
|
| 47 |
template<typename T> requires C1<T> || C2<T> |
| 48 |
constexpr int f<T> = 3; |
| 49 |
|
| 50 |
static_assert(f<unsigned> == 2); |
| 51 |
static_assert(f<char[10]> == 3); |
| 52 |
static_assert(f<char> == 1); |
| 53 |
|
| 54 |
template <int I> |
| 55 |
struct S { |
| 56 |
template <typename T> |
| 57 |
static constexpr int f = 1; |
| 58 |
|
| 59 |
template <typename T> |
| 60 |
requires C1<T> && C2<T> |
| 61 |
static constexpr int f<T> = 2; |
| 62 |
|
| 63 |
template <typename T> |
| 64 |
requires C1<T> || C2<T> |
| 65 |
static constexpr int f<T> = 3; |
| 66 |
}; |
| 67 |
|
| 68 |
static_assert(S<1>::f<unsigned> == 2); |
| 69 |
static_assert(S<1>::f<char[10]> == 3); |
| 70 |
static_assert(S<1>::f<char> == 1); |