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