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
6 const T
& min(const T
&, const T
&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}
9 (void)min(1, 2l); // expected-error{{no matching function for call to 'min'}}
12 template<typename R
, typename T
>
13 R
*dyn_cast(const T
&); // expected-note{{candidate template ignored: couldn't infer template argument 'R'}}
15 void test_dyn_cast(int* ptr
) {
16 (void)dyn_cast(ptr
); // expected-error{{no matching function for call to 'dyn_cast'}}
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}}
24 void test_get(void *ptr
) {
25 get
<int>(ptr
); // expected-error{{no matching function for call to 'get'}}
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 '::'}}
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}}
33 void test_get_type(int *ptr
) {
34 (void)get_type(ptr
); // expected-error{{no matching function for call to 'get_type'}}
39 const T
& min(const T
&, const T
&); // expected-note{{candidate template ignored: deduced conflicting types for parameter 'T' ('int' vs. 'long')}}
42 void test_X_min(X x
) {
43 (void)x
.min(1, 2l); // expected-error{{no matching member function for call to 'min'}}
47 template<bool, typename
= void> struct enable_if
{};
48 template<typename T
> struct enable_if
<true, T
> { typedef T type
; };
50 template<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]}}
51 int k
= if_size_4
<char>(); // expected-error{{no matching function}}
54 template<typename Cond
, typename T
= void> struct enable_if
: boost::enable_if
<Cond::value
, T
> {};
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]}}
60 if_int
<char>(); // expected-error{{no matching function}}
63 template<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}}
66 NonTemplateFunction
<char> NTFC
; // expected-note{{here}}
79 void foo(NS2::array
<A
>); // expected-note{{candidate template ignored: could not match 'NS2::array' against 'NS1::array'}}
82 foo(NS1::array
<int>()); // expected-error{{no matching function for call to 'foo'}}
86 template<bool, typename
= void> struct enable_if
{};
87 template<typename T
> struct enable_if
<true, T
> { typedef T type
; };
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
;
96 struct a_trait
: std::false_type
{};
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}}
103 // expected-note@+1 {{candidate template ignored: requirement 'a_trait<int>::value' was not satisfied [with T = int]}}
105 void bar() { foo
<int>(); } // expected-error {{no matching function for call to 'foo'}}
109 struct some_trait
: std::false_type
{};
111 // FIXME: It would be nice to tunnel the 'disabled by enable_if' diagnostic through here.
113 struct a_pony
: std::enable_if
<some_trait
<T
>::value
> {};
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}}
120 // 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'}}
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}}
131 // expected-note@+7 {{candidate template ignored: requirement 'some_trait<int>::value' was not satisfied [with T = int]}}
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}}
139 void wobble() { wibble
<int>(); } // expected-error {{no matching function for call to 'wibble'}}
142 struct some_passing_trait
: std::true_type
{};
144 #if __cplusplus <= 199711L
145 // 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}}
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 || (some_passing_trait<int>::value && 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'}}
154 #define CONCEPT_REQUIRES_(...) \
156 typename std::enable_if<(x == 43) || (__VA_ARGS__)>::type = 0
158 #if __cplusplus <= 199711L
159 // 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}}
163 CONCEPT_REQUIRES_(some_passing_trait
<T
>::value
&& some_trait
<T
>::value
)>
164 void rangesv3(); // expected-note{{candidate template ignored: requirement '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'}}