167 lines · cpp
1// RUN: %clang_cc1 -fsyntax-only -verify %s2// RUN: %clang_cc1 -fsyntax-only -verify -std=c++98 %s3// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s4 5template<typename T>6const T& min(const T&, const T&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}7 8void test_min() {9 (void)min(1, 2l); // expected-error{{no matching function for call to 'min'}}10}11 12template<typename R, typename T>13R *dyn_cast(const T&); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}}14 15void test_dyn_cast(int* ptr) {16 (void)dyn_cast(ptr); // expected-error{{no matching function for call to 'dyn_cast'}}17}18 19template<int I, typename T>20 void get(const T&); // expected-note{{candidate template ignored: invalid explicitly-specified argument for template parameter 'I'}}21template<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 24void test_get(void *ptr) {25 get<int>(ptr); // expected-error{{no matching function for call to 'get'}}26}27 28template<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 '::'}}30template<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 33void test_get_type(int *ptr) {34 (void)get_type(ptr); // expected-error{{no matching function for call to 'get_type'}}35}36 37struct 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 42void test_X_min(X x) {43 (void)x.min(1, 2l); // expected-error{{no matching member function for call to 'min'}}44}45 46namespace boost {47 template<bool, typename = void> struct enable_if {};48 template<typename T> struct enable_if<true, T> { typedef T type; };49}50template<typename T> typename boost::enable_if<sizeof(T) == 4, int>::type if_size_4(); // expected-note{{candidate template ignored: requirement 'sizeof(char) == 4' was not satisfied [with T = char]}}51int k = if_size_4<char>(); // expected-error{{no matching function}}52 53namespace llvm {54 template<typename Cond, typename T = void> struct enable_if : boost::enable_if<Cond::value, T> {};55}56template<typename T> struct is_int { enum { value = false }; };57template<> struct is_int<int> { enum { value = true }; };58template<typename T> typename llvm::enable_if<is_int<T> >::type if_int(); // expected-note{{candidate template ignored: disabled by 'enable_if' [with T = char]}}59void test_if_int() {60 if_int<char>(); // expected-error{{no matching function}}61}62 63template<typename T> struct NonTemplateFunction {64 typename boost::enable_if<sizeof(T) == 4, int>::type f(); // expected-error{{failed requirement 'sizeof(char) == 4'; 'enable_if' cannot be used to disable this declaration}}65};66NonTemplateFunction<char> NTFC; // expected-note{{here}}67 68namespace NS1 {69 template <class A>70 class array {};71}72 73namespace NS2 {74 template <class A>75 class array {};76}77 78template <class A>79void foo(NS2::array<A>); // expected-note{{candidate template ignored: could not match 'NS2::array' against 'NS1::array'}}80 81void test() {82 foo(NS1::array<int>()); // expected-error{{no matching function for call to 'foo'}}83}84 85namespace 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 94namespace 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 <= 199711L101 // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}}102#endif103 // expected-note@+1 {{candidate template ignored: requirement 'PR15673::a_trait<int>::value' was not satisfied [with T = int]}}104 void foo() {}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 <= 199711L118 // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}}119#endif120 // FIXME: The source location here is poor.121 void baz() { } // expected-note {{candidate template ignored: substitution failure [with T = int]: no type named 'type' in 'PR15673::a_pony<int>'}}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 <= 199711L129 // expected-warning@-2 {{alias declarations are a C++11 extension}}130#endif131 // expected-note@+7 {{candidate template ignored: requirement 'PR15673::some_trait<int>::value' was not satisfied [with T = int]}}132 133 template<typename T,134 typename Requires = unicorns<T> >135#if __cplusplus <= 199711L136 // expected-warning@-2 {{default template arguments for a function template are a C++11 extension}}137#endif138 void wibble() {}139 void wobble() { wibble<int>(); } // expected-error {{no matching function for call to 'wibble'}}140 141 template<typename T>142 struct some_passing_trait : std::true_type {};143 144#if __cplusplus <= 199711L145 // expected-warning@+4 {{default template arguments for a function template are a C++11 extension}}146 // expected-warning@+4 {{default template arguments for a function template are a C++11 extension}}147#endif148 template<typename T,149 int n = 42,150 typename std::enable_if<n == 43 || (some_passing_trait<T>::value && some_trait<T>::value), int>::type = 0>151 void almost_rangesv3(); // expected-note{{candidate template ignored: requirement '42 == 43 || (PR15673::some_passing_trait<int>::value && PR15673::some_trait<int>::value)' was not satisfied}}152 void test_almost_rangesv3() { almost_rangesv3<int>(); } // expected-error{{no matching function for call to 'almost_rangesv3'}}153 154 #define CONCEPT_REQUIRES_(...) \155 int x = 42, \156 typename std::enable_if<(x == 43) || (__VA_ARGS__)>::type = 0157 158#if __cplusplus <= 199711L159 // expected-warning@+4 {{default template arguments for a function template are a C++11 extension}}160 // expected-warning@+3 {{default template arguments for a function template are a C++11 extension}}161#endif162 template<typename T,163 CONCEPT_REQUIRES_(some_passing_trait<T>::value && some_trait<T>::value)>164 void rangesv3(); // expected-note{{candidate template ignored: requirement 'PR15673::some_trait<int>::value' was not satisfied [with T = int, x = 42]}}165 void test_rangesv3() { rangesv3<int>(); } // expected-error{{no matching function for call to 'rangesv3'}}166}167