| 1 |
// RUN: %clang_cc1 -std=c++2a -x c++ -verify %s |
| 2 |
|
| 3 |
template<typename T> |
| 4 |
concept C1 = sizeof(T) == 1; |
| 5 |
// expected-note@-1 2{{because 'sizeof(short) == 1' (2 == 1) evaluated to false}} |
| 6 |
// expected-note@-2 {{because 'sizeof(int) == 1' (4 == 1) evaluated to false}} |
| 7 |
|
| 8 |
template<C1 T> // expected-note {{because 'int' does not satisfy 'C1'}} |
| 9 |
using A = T; |
| 10 |
|
| 11 |
using a1 = A<int>; // expected-error {{constraints not satisfied for alias template 'A' [with T = int]}} |
| 12 |
using a2 = A<char>; |
| 13 |
|
| 14 |
template<typename T> |
| 15 |
concept C2 = sizeof(T) == 2; |
| 16 |
// expected-note@-1 {{because 'sizeof(char) == 2' (1 == 2) evaluated to false}} |
| 17 |
|
| 18 |
template<C1 T1, C2 T2> |
| 19 |
// expected-note@-1 2{{because 'short' does not satisfy 'C1'}} |
| 20 |
// expected-note@-2 {{because 'char' does not satisfy 'C2'}} |
| 21 |
using B = T1; |
| 22 |
|
| 23 |
using b1 = B<char, short>; |
| 24 |
using b2 = B<char, char>; // expected-error {{constraints not satisfied for alias template 'B' [with T1 = char, T2 = char]}} |
| 25 |
using b3 = B<short, short>; // expected-error {{constraints not satisfied for alias template 'B' [with T1 = short, T2 = short]}} |
| 26 |
using b4 = B<short, char>; // expected-error {{constraints not satisfied for alias template 'B' [with T1 = short, T2 = char]}} |
| 27 |
|
| 28 |
template<typename... T> |
| 29 |
concept C3 = (sizeof(T) + ...) == 12; |
| 30 |
// expected-note@-1 {{because 'sizeof(char[11]) == 12' (11 == 12) evaluated to false}} |
| 31 |
// expected-note@-2 {{because 'sizeof(char[10]) == 12' (10 == 12) evaluated to false}} |
| 32 |
// expected-note@-3 3{{because 'sizeof(int) == 12' (4 == 12) evaluated to false}} |
| 33 |
// expected-note@-4 6{{because 'sizeof(short) == 12' (2 == 12) evaluated to false}} |
| 34 |
|
| 35 |
template<C3 T1, C3 T2, C3 T3> |
| 36 |
// expected-note@-1 {{because 'char[11]' does not satisfy 'C3'}} |
| 37 |
// expected-note@-2 {{because 'char[10]' does not satisfy 'C3'}} |
| 38 |
using C = T2; |
| 39 |
|
| 40 |
using c1 = C<char[12], int[3], short[6]>; |
| 41 |
using c2 = C<char[12], char[11], char[10]>; |
| 42 |
// expected-error@-1 {{constraints not satisfied for alias template 'C' [with T1 = char[12], T2 = char[11], T3 = char[10]]}} |
| 43 |
using c3 = C<char[12], char[12], char[10]>; |
| 44 |
// expected-error@-1 {{constraints not satisfied for alias template 'C' [with T1 = char[12], T2 = char[12], T3 = char[10]]}} |
| 45 |
|
| 46 |
template<C3... Ts> |
| 47 |
// expected-note@-1 {{because 'int' does not satisfy 'C3'}} |
| 48 |
// expected-note@-2 2{{and 'int' does not satisfy 'C3'}} |
| 49 |
// expected-note@-3 {{because 'short' does not satisfy 'C3'}} |
| 50 |
// expected-note@-4 5{{and 'short' does not satisfy 'C3'}} |
| 51 |
using D = int; |
| 52 |
|
| 53 |
using d1 = D<char[12], int[3], short[6]>; |
| 54 |
using d2 = D<int, int, int>; |
| 55 |
// expected-error@-1 {{constraints not satisfied for alias template 'D' [with Ts = <int, int, int>}} |
| 56 |
using d3 = D<short, short, short, short, short, short>; |
| 57 |
// expected-error@-1 {{constraints not satisfied for alias template 'D' [with Ts = <short, short, short, short, short, short>}} |
| 58 |
|
| 59 |
template<typename T> |
| 60 |
concept C4 = sizeof(T) == 4; |
| 61 |
// expected-note@-1 3{{because 'sizeof(char) == 4' (1 == 4) evaluated to false}} |
| 62 |
|
| 63 |
template<C4... Ts> |
| 64 |
// expected-note@-1 2{{because 'char' does not satisfy 'C4'}} |
| 65 |
// expected-note@-2 {{and 'char' does not satisfy 'C4'}} |
| 66 |
using E = int; |
| 67 |
|
| 68 |
using e1 = E<int>; |
| 69 |
using e2 = E<char, int>; // expected-error {{constraints not satisfied for alias template 'E' [with Ts = <char, int>]}} |
| 70 |
using e3 = E<char, char>; // expected-error {{constraints not satisfied for alias template 'E' [with Ts = <char, char>]}} |
| 71 |
using e4 = E<>; |
| 72 |
|
| 73 |
template<typename T, typename U> |
| 74 |
constexpr bool is_same_v = false; |
| 75 |
|
| 76 |
template<typename T> |
| 77 |
constexpr bool is_same_v<T, T> = true; |
| 78 |
|
| 79 |
template<typename T, typename U> |
| 80 |
concept Same = is_same_v<T, U>; // expected-note {{because 'is_same_v<long, int>' evaluated to false}} |
| 81 |
|
| 82 |
template<Same<int> T> // expected-note {{because 'Same<long, int>' evaluated to false}} |
| 83 |
using F = T; |
| 84 |
|
| 85 |
using f1 = F<int>; |
| 86 |
using f2 = F<long>; // expected-error {{constraints not satisfied for alias template 'F' [with T = long]}} |
| 87 |
|
| 88 |
template<typename T, typename... Ts> |
| 89 |
concept OneOf = (is_same_v<T, Ts> || ...); // #OneOf |
| 90 |
// expected-note@#OneOf 2{{because 'is_same_v<char, char[1]>' evaluated to false}} |
| 91 |
// expected-note@#OneOf 2{{and 'is_same_v<char, char[2]>' evaluated to false}} |
| 92 |
// expected-note@#OneOf {{because 'is_same_v<short, int>' evaluated to false}} |
| 93 |
// expected-note@#OneOf {{and 'is_same_v<short, long>' evaluated to false}} |
| 94 |
// expected-note@#OneOf {{and 'is_same_v<short, char>' evaluated to false}} |
| 95 |
// expected-note@#OneOf 3{{because 'is_same_v<int, char[1]>' evaluated to false}} |
| 96 |
// expected-note@#OneOf 3{{and 'is_same_v<int, char[2]>' evaluated to false}} |
| 97 |
// expected-note@#OneOf {{because 'is_same_v<decltype(nullptr), char>' evaluated to false}} |
| 98 |
// expected-note@#OneOf {{because 'is_same_v<std::nullptr_t, char>' evaluated to false}} |
| 99 |
// expected-note@#OneOf {{and 'is_same_v<std::nullptr_t, int>' evaluated to false}} |
| 100 |
// expected-note@#OneOf {{and 'is_same_v<decltype(nullptr), int>' evaluated to false}} |
| 101 |
|
| 102 |
template<OneOf<char[1], char[2]> T, OneOf<int, long, char> U> |
| 103 |
// expected-note@-1 2{{because 'OneOf<char, char[1], char[2]>' evaluated to false}} |
| 104 |
// expected-note@-2 {{because 'OneOf<short, int, long, char>' evaluated to false}} |
| 105 |
using G = T; |
| 106 |
|
| 107 |
using g1 = G<char[1], int>; |
| 108 |
using g2 = G<char, int>; // expected-error{{constraints not satisfied for alias template 'G' [with T = char, U = int]}} |
| 109 |
using g3 = G<char[1], short>; // expected-error{{constraints not satisfied for alias template 'G' [with T = char[1], U = short]}} |
| 110 |
using g4 = G<char, short>; // expected-error{{constraints not satisfied for alias template 'G' [with T = char, U = short]}} |
| 111 |
|
| 112 |
template<OneOf<char[1], char[2]>... Ts> |
| 113 |
// expected-note@-1 2{{because 'OneOf<int, char[1], char[2]>' evaluated to false}} |
| 114 |
// expected-note@-2 {{and 'OneOf<int, char[1], char[2]>' evaluated to false}} |
| 115 |
using H = int; |
| 116 |
|
| 117 |
using h1 = H<char[1], int>; |
| 118 |
// expected-error@-1 {{constraints not satisfied for alias template 'H' [with Ts = <char[1], int>]}} |
| 119 |
using h2 = H<int, int>; |
| 120 |
// expected-error@-1 {{constraints not satisfied for alias template 'H' [with Ts = <int, int>]}} |
| 121 |
using h3 = H<char[1], char[2]>; |
| 122 |
|
| 123 |
template<OneOf<char, int> auto x> |
| 124 |
// expected-note@-1 {{because 'OneOf<decltype(nullptr), char, int>' evaluated to false}} |
| 125 |
using I = int; |
| 126 |
|
| 127 |
using i1 = I<1>; |
| 128 |
using i2 = I<'a'>; |
| 129 |
// FIXME: This crashes with -std=c++2c |
| 130 |
using i3 = I<nullptr>; |
| 131 |
// expected-error@-1 {{constraints not satisfied for alias template 'I' [with x = nullptr]}} |
| 132 |
|
| 133 |
template<OneOf<char, int> auto... x> |
| 134 |
// expected-note@-1 {{because 'OneOf<decltype(nullptr), char, int>' evaluated to false}} |
| 135 |
using J = int; |
| 136 |
|
| 137 |
using j1 = J<1, 'b'>; |
| 138 |
using j2 = J<'a', nullptr>; |
| 139 |
// expected-error@-1 {{constraints not satisfied for alias template 'J' [with x = <'a', nullptr>]}} |
| 140 |
|
| 141 |
template<OneOf<char, int> auto &x> |
| 142 |
// expected-error@-1 {{constrained placeholder types other than simple 'auto' on non-type template parameters not supported yet}} |
| 143 |
using K = int; |