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