1 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -emit-llvm-only %s
2 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -fdelayed-template-parsing %s
3 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -fms-extensions %s
4 // RUN: %clang_cc1 -std=c++11 -verify -fsyntax-only -fdelayed-template-parsing -fms-extensions %s
6 template<class T
, class U
> struct is_same
{ enum { value
= false }; };
7 template<class T
> struct is_same
<T
, T
> { enum { value
= true }; };
9 namespace test_sfinae_and_delete
{
12 template<class T
> double f(T
) = delete; //expected-note{{candidate}}
13 char f(...); //expected-note{{candidate}}
15 static_assert(is_same
<decltype(f(3)),char>::value
, ""); //expected-error{{call to deleted function}} expected-error{{static assertion failed}}
17 template<class T
> decltype(f(T
{})) g(T
); // this one sfinae's out.
18 template<class T
> int *g(T
);
25 template<class T
> double* f(T
);
26 template<> double* f(double) = delete;
28 template<class T
> decltype(f(T
{})) g(T
); // expected-note{{candidate}}
29 template<class T
> int *g(T
); //expected-note{{candidate}}
31 double *dp
= g(3); //expected-error{{ambiguous}}
32 int *ip
= g(3.14); // this is OK - because the explicit specialization is deleted and sfinae's out one of the template candidates
38 template<class T
> double* f(T
) = delete;
39 template<> double* f(double);
41 template<class T
> decltype(f(T
{})) g(T
); // expected-note{{candidate}}
42 template<class T
> int *g(T
); //expected-note{{candidate}}
45 int *dp
= g(3); // this is OK - because the non-double specializations are deleted and sfinae's out one of the template candidates
46 double *ip
= g(3.14); //expected-error{{ambiguous}}
50 } // end ns test_sfinae_and_delete
52 namespace test_explicit_specialization_of_member
{
54 template<class T
> struct X
{
57 template<> int* X
<int>::f(int) { }
59 template<class T
> decltype(X
<T
>{}.f(T
{})) g(T
); // expected-note{{candidate}}
60 template<class T
> int *g(T
); //expected-note{{candidate}}
63 int *ip2
= g(3.14); // this is OK - because the non-int specializations are deleted and sfinae's out one of the template candidates
64 int *ip
= g(3); //expected-error{{ambiguous}}
71 template<class T
> double* f(T
) = delete;
73 template<> double* X::f(int);
75 template<class T
> decltype(X
{}.f(T
{})) g(T
); // expected-note{{candidate}}
76 template<class T
> int *g(T
); //expected-note{{candidate}}
79 int *ip2
= g(3.14); // this is OK - because the non-int specializations are deleted and sfinae's out one of the template candidates
80 int *ip
= g(3); //expected-error{{ambiguous}}
86 template<class T
> struct X
{
87 template<class U
> double *f1(U
, T
) = delete;
88 template<class U
> double *f2(U
, T
) = delete;
90 template<> template<> double* X
<int>::f1(int, int);
91 template<> template<class U
> double* X
<int>::f2(U
, int);
93 template<class T
, class U
> decltype(X
<T
>{}.f1(U
{}, T
{})) g1(U
, T
); // expected-note{{candidate}}
94 template<class T
, class U
> int *g1(U
, T
); //expected-note{{candidate}}
96 template<class T
, class U
> decltype(X
<T
>{}.f2(U
{}, T
{})) g2(U
, T
); // expected-note2{{candidate}}
97 template<class T
, class U
> int *g2(U
, T
); //expected-note2{{candidate}}
101 int *ip2
= g1(3.14, 3); // this is OK - because the non-int specializations are deleted and sfinae's out one of the template candidates
102 int *ip
= g1(3, 3); //expected-error{{ambiguous}}
104 int *ip3
= g2(3.14, 3); //expected-error{{ambiguous}}
105 int *ip4
= g2(3, 3); //expected-error{{ambiguous}}
108 int *ip3
= g2(3.14, 3.14);
109 int *ip4
= g2(3, 3.14);
117 template < typename T
> T
* foo (T
);
118 template <> int* foo(int) = delete;
119 template <> int* foo(int); //expected-note{{candidate}}
121 int *IP
= foo(2); //expected-error{{deleted}}
122 double *DP
= foo(3.14);
126 template < typename T
> T
* foo (T
);
127 template <> int* foo(int); //expected-note{{previous}}
128 template <> int* foo(int) = delete; //expected-error{{deleted definition must be first declaration}}
133 } // end test_explicit_specializations_and_delete