1*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify %s
2*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s
3*67e74705SXin Li // RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
4*67e74705SXin Li
5*67e74705SXin Li template<typename T>
6*67e74705SXin Li const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}
7*67e74705SXin Li
test_min()8*67e74705SXin Li void test_min() {
9*67e74705SXin Li (void)min(1, 2l); // expected-error{{no matching function for call to 'min'}}
10*67e74705SXin Li }
11*67e74705SXin Li
12*67e74705SXin Li template<typename R, typename T>
13*67e74705SXin Li R *dyn_cast(const T&); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}}
14*67e74705SXin Li
test_dyn_cast(int * ptr)15*67e74705SXin Li void test_dyn_cast(int* ptr) {
16*67e74705SXin Li (void)dyn_cast(ptr); // expected-error{{no matching function for call to 'dyn_cast'}}
17*67e74705SXin Li }
18*67e74705SXin Li
19*67e74705SXin Li template<int I, typename T>
20*67e74705SXin Li void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for template parameter 'I'}}
21*67e74705SXin Li template<template<class T> class, typename T>
22*67e74705SXin Li void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for 1st template parameter}}
23*67e74705SXin Li
test_get(void * ptr)24*67e74705SXin Li void test_get(void *ptr) {
25*67e74705SXin Li get<int>(ptr); // expected-error{{no matching function for call to 'get'}}
26*67e74705SXin Li }
27*67e74705SXin Li
28*67e74705SXin Li template<typename T>
29*67e74705SXin Li typename T::type get_type(const T&); // expected-note{{candidate template ignored: substitution failure [with T = int *]: type 'int *' cannot be used prior to '::'}}
30*67e74705SXin Li template<typename T>
31*67e74705SXin Li void get_type(T *, int[(int)sizeof(T) - 9] = 0); // expected-note{{candidate template ignored: substitution failure [with T = int]: array size is negative}}
32*67e74705SXin Li
test_get_type(int * ptr)33*67e74705SXin Li void test_get_type(int *ptr) {
34*67e74705SXin Li (void)get_type(ptr); // expected-error{{no matching function for call to 'get_type'}}
35*67e74705SXin Li }
36*67e74705SXin Li
37*67e74705SXin Li struct X {
38*67e74705SXin Li template<typename T>
39*67e74705SXin Li const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}
40*67e74705SXin Li };
41*67e74705SXin Li
test_X_min(X x)42*67e74705SXin Li void test_X_min(X x) {
43*67e74705SXin Li (void)x.min(1, 2l); // expected-error{{no matching member function for call to 'min'}}
44*67e74705SXin Li }
45*67e74705SXin Li
46*67e74705SXin Li namespace boost {
47*67e74705SXin Li template<bool, typename = void> struct enable_if {};
48*67e74705SXin Li template<typename T> struct enable_if<true, T> { typedef T type; };
49*67e74705SXin Li }
50*67e74705SXin Li template<typename T> typename boost::enable_if<sizeof(T) == 4, int>::type if_size_4(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}}
51*67e74705SXin Li int k = if_size_4<char>(); // expected-error{{no matching function}}
52*67e74705SXin Li
53*67e74705SXin Li namespace llvm {
54*67e74705SXin Li template<typename Cond, typename T = void> struct enable_if : boost::enable_if<Cond::value, T> {};
55*67e74705SXin Li }
56*67e74705SXin Li template<typename T> struct is_int { enum { value = false }; };
57*67e74705SXin Li template<> struct is_int<int> { enum { value = true }; };
58*67e74705SXin Li template<typename T> typename llvm::enable_if<is_int<T> >::type if_int(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}}
test_if_int()59*67e74705SXin Li void test_if_int() {
60*67e74705SXin Li if_int<char>(); // expected-error{{no matching function}}
61*67e74705SXin Li }
62*67e74705SXin Li
63*67e74705SXin Li template<typename T> struct NonTemplateFunction {
64*67e74705SXin Li typename boost::enable_if<sizeof(T) == 4, int>::type f(); // expected-error{{no type named 'type' in 'boost::enable_if<false, int>'; 'enable_if' cannot be used to disable this declaration}}
65*67e74705SXin Li };
66*67e74705SXin Li NonTemplateFunction<char> NTFC; // expected-note{{here}}
67*67e74705SXin Li
68*67e74705SXin Li namespace NS1 {
69*67e74705SXin Li template <class A>
70*67e74705SXin Li class array {};
71*67e74705SXin Li }
72*67e74705SXin Li
73*67e74705SXin Li namespace NS2 {
74*67e74705SXin Li template <class A>
75*67e74705SXin Li class array {};
76*67e74705SXin Li }
77*67e74705SXin Li
78*67e74705SXin Li template <class A>
79*67e74705SXin Li void foo(NS2::array<A>); // expected-note{{candidate template ignored: could not match 'NS2::array' against 'NS1::array'}}
80*67e74705SXin Li
test()81*67e74705SXin Li void test() {
82*67e74705SXin Li foo(NS1::array<int>()); // expected-error{{no matching function for call to 'foo'}}
83*67e74705SXin Li }
84*67e74705SXin Li
85*67e74705SXin Li namespace std {
86*67e74705SXin Li template<bool, typename = void> struct enable_if {};
87*67e74705SXin Li template<typename T> struct enable_if<true, T> { typedef T type; };
88*67e74705SXin Li
89*67e74705SXin Li template<typename T, T V> struct integral_constant { static const T value = V; };
90*67e74705SXin Li typedef integral_constant<bool, false> false_type;
91*67e74705SXin Li typedef integral_constant<bool, true> true_type;
92*67e74705SXin Li };
93*67e74705SXin Li
94*67e74705SXin Li namespace PR15673 {
95*67e74705SXin Li template<typename T>
96*67e74705SXin Li struct a_trait : std::false_type {};
97*67e74705SXin Li
98*67e74705SXin Li template<typename T,
99*67e74705SXin Li typename Requires = typename std::enable_if<a_trait<T>::value>::type>
100*67e74705SXin Li #if __cplusplus <= 199711L
101*67e74705SXin Li // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}}
102*67e74705SXin Li #endif
103*67e74705SXin Li // expected-note@-4 {{candidate template ignored: disabled by 'enable_if' [with T = int]}}
foo()104*67e74705SXin Li void foo() {}
bar()105*67e74705SXin Li void bar() { foo<int>(); } // expected-error {{no matching function for call to 'foo'}}
106*67e74705SXin Li
107*67e74705SXin Li
108*67e74705SXin Li template<typename T>
109*67e74705SXin Li struct some_trait : std::false_type {};
110*67e74705SXin Li
111*67e74705SXin Li // FIXME: It would be nice to tunnel the 'disabled by enable_if' diagnostic through here.
112*67e74705SXin Li template<typename T>
113*67e74705SXin Li struct a_pony : std::enable_if<some_trait<T>::value> {};
114*67e74705SXin Li
115*67e74705SXin Li template<typename T,
116*67e74705SXin Li typename Requires = typename a_pony<T>::type>
117*67e74705SXin Li #if __cplusplus <= 199711L
118*67e74705SXin Li // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}}
119*67e74705SXin Li #endif
120*67e74705SXin Li // FIXME: The source location here is poor.
baz()121*67e74705SXin Li void baz() { } // expected-note {{candidate template ignored: substitution failure [with T = int]: no type named 'type' in 'PR15673::a_pony<int>'}}
quux()122*67e74705SXin Li void quux() { baz<int>(); } // expected-error {{no matching function for call to 'baz'}}
123*67e74705SXin Li
124*67e74705SXin Li
125*67e74705SXin Li // FIXME: This note doesn't make it clear which candidate we rejected.
126*67e74705SXin Li template <typename T>
127*67e74705SXin Li using unicorns = typename std::enable_if<some_trait<T>::value>::type;
128*67e74705SXin Li #if __cplusplus <= 199711L
129*67e74705SXin Li // expected-warning@-2 {{alias declarations are a C++11 extension}}
130*67e74705SXin Li #endif
131*67e74705SXin Li // expected-note@-4 {{candidate template ignored: disabled by 'enable_if' [with T = int]}}
132*67e74705SXin Li
133*67e74705SXin Li template<typename T,
134*67e74705SXin Li typename Requires = unicorns<T> >
135*67e74705SXin Li #if __cplusplus <= 199711L
136*67e74705SXin Li // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}}
137*67e74705SXin Li #endif
wibble()138*67e74705SXin Li void wibble() {}
wobble()139*67e74705SXin Li void wobble() { wibble<int>(); } // expected-error {{no matching function for call to 'wibble'}}
140*67e74705SXin Li }
141