| 1 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s |
| 2 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++14 %s |
| 3 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++17 %s |
| 4 |
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++20 %s |
| 5 |
|
| 6 |
namespace std { |
| 7 |
inline namespace __1 { |
| 8 |
template<bool, class = void> struct enable_if {}; |
| 9 |
template<class T> struct enable_if<true, T> { using type = T; }; |
| 10 |
template<bool B, class T = void> using enable_if_t = typename enable_if<B, T>::type; |
| 11 |
} |
| 12 |
} |
| 13 |
|
| 14 |
namespace similar_to_user_code { |
| 15 |
// expected-note@+2 {{candidate template ignored: requirement 'sizeof(char) != 1' was not satisfied [with T = char]}} |
| 16 |
template<class T, class = std::enable_if_t<sizeof(T) != 1>> |
| 17 |
void f(T, short); |
| 18 |
|
| 19 |
// expected-note@+2 {{candidate template ignored: requirement 'sizeof(char) != 1' was not satisfied [with T = char]}} |
| 20 |
template<class T, std::enable_if_t<sizeof(T) != 1>* = nullptr> |
| 21 |
void f(T, int); |
| 22 |
|
| 23 |
// expected-note@+2 {{candidate template ignored: requirement 'sizeof(char) != 1' was not satisfied [with T = char]}} |
| 24 |
template<class T> |
| 25 |
std::enable_if_t<sizeof(T) != 1, void> f(T, long); |
| 26 |
|
| 27 |
void test() { |
| 28 |
f('x', 0); // expected-error{{no matching function}} |
| 29 |
} |
| 30 |
} |
| 31 |
|
| 32 |
namespace similar_to_libcxx_version_14 { |
| 33 |
template<bool, class = void> struct enable_if {}; |
| 34 |
template<class T> struct enable_if<true, T> { using type = T; }; |
| 35 |
template<bool B, class T = void> using __enable_if_t = typename enable_if<B, T>::type; |
| 36 |
|
| 37 |
// expected-note@+2 {{candidate template ignored: requirement 'sizeof(char) != 1' was not satisfied [with T = char]}} |
| 38 |
template<class T, class = __enable_if_t<sizeof(T) != 1>> |
| 39 |
void f(T, short); |
| 40 |
|
| 41 |
// expected-note@+2 {{candidate template ignored: requirement 'sizeof(char) != 1' was not satisfied [with T = char]}} |
| 42 |
template<class T, __enable_if_t<sizeof(T) != 1>* = nullptr> |
| 43 |
void f(T, int); |
| 44 |
|
| 45 |
// expected-note@+2 {{candidate template ignored: requirement 'sizeof(char) != 1' was not satisfied [with T = char]}} |
| 46 |
template<class T> |
| 47 |
__enable_if_t<sizeof(T) != 1, void> f(T, long); |
| 48 |
|
| 49 |
void test() { |
| 50 |
f('x', 0); // expected-error{{no matching function}} |
| 51 |
} |
| 52 |
} |
| 53 |
|
| 54 |
namespace similar_to_libcxx_version_13 { |
| 55 |
template<bool> struct _MetaBase {}; |
| 56 |
template<> struct _MetaBase<true> { template<class R> using _EnableIfImpl = R; }; |
| 57 |
template<bool B, class T = void> using _EnableIf = typename _MetaBase<B>::template _EnableIfImpl<T>; |
| 58 |
|
| 59 |
// expected-note@+2 {{no member named '_EnableIfImpl'}} |
| 60 |
template<class T, class = _EnableIf<sizeof(T) != 1>> |
| 61 |
void f(T, short); |
| 62 |
|
| 63 |
// expected-note@+2 {{no member named '_EnableIfImpl'}} |
| 64 |
template<class T, _EnableIf<sizeof(T) != 1>* = nullptr> |
| 65 |
void f(T, int); |
| 66 |
|
| 67 |
// expected-note@+2 {{no member named '_EnableIfImpl'}} |
| 68 |
template<class T> |
| 69 |
_EnableIf<sizeof(T) != 1, void> f(T, long); |
| 70 |
|
| 71 |
void test() { |
| 72 |
f('x', 0); // expected-error{{no matching function}} |
| 73 |
} |
| 74 |
} |
| 75 |
|
| 76 |
namespace not_all_names_are_magic { |
| 77 |
template<bool, class = void> struct enable_if {}; |
| 78 |
template<class T> struct enable_if<true, T> { using type = T; }; |
| 79 |
template<bool B, class T = void> using a_pony = typename enable_if<B, T>::type; |
| 80 |
|
| 81 |
// expected-note@-2 {{candidate template ignored: disabled by 'enable_if' [with T = char]}} |
| 82 |
template<class T, class = a_pony<sizeof(T) != 1>> |
| 83 |
void f(T, short); |
| 84 |
|
| 85 |
// expected-note@-6 {{candidate template ignored: disabled by 'enable_if' [with T = char]}} |
| 86 |
template<class T, a_pony<sizeof(T) != 1>* = nullptr> |
| 87 |
void f(T, int); |
| 88 |
|
| 89 |
// expected-note@-10 {{candidate template ignored: disabled by 'enable_if' [with T = char]}} |
| 90 |
template<class T> |
| 91 |
a_pony<sizeof(T) != 1, void> f(T, long); |
| 92 |
|
| 93 |
void test() { |
| 94 |
f('x', 0); // expected-error{{no matching function}} |
| 95 |
} |
| 96 |
} |