[clang] Handle __declspec() attributes in using
[llvm-project.git] / clang / test / SemaTemplate / diagnose-enable-if-t.cpp
blob3cf142907cd7fb0778d8e70d4986becefe9ae547
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
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;
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);
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);
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);
27 void test() {
28 f('x', 0); // expected-error{{no matching function}}
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;
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);
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);
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);
49 void test() {
50 f('x', 0); // expected-error{{no matching function}}
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>;
59 // expected-note@+2 {{no member named '_EnableIfImpl'}}
60 template<class T, class = _EnableIf<sizeof(T) != 1>>
61 void f(T, short);
63 // expected-note@+2 {{no member named '_EnableIfImpl'}}
64 template<class T, _EnableIf<sizeof(T) != 1>* = nullptr>
65 void f(T, int);
67 // expected-note@+2 {{no member named '_EnableIfImpl'}}
68 template<class T>
69 _EnableIf<sizeof(T) != 1, void> f(T, long);
71 void test() {
72 f('x', 0); // expected-error{{no matching function}}
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;
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);
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);
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);
93 void test() {
94 f('x', 0); // expected-error{{no matching function}}