1 // RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify %s
2 // RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify -std=c++98 %s
3 // RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify -std=c++11 %s
5 int* f(int) { return 0; }
6 float* f(float) { return 0; }
9 void test_f(int iv
, float fv
) {
14 int* g(int, float, int); // expected-note {{candidate function}}
15 float* g(int, int, int);
16 double* g(int, float, float); // expected-note {{candidate function}}
17 char* g(int, float, ...);
20 void test_g(int iv
, float fv
) {
21 int* ip1
= g(iv
, fv
, 0);
22 float* fp1
= g(iv
, iv
, 0);
23 double* dp1
= g(iv
, fv
, fv
);
25 char* cp2
= g(0, 0, 0, iv
, fv
);
27 double* dp2
= g(0, fv
, 1.5); // expected-error {{call to 'g' is ambiguous}}
33 void test_h(float fv
, unsigned char cv
) {
41 void test_i(short sv
, int iv
, long lv
, unsigned char ucv
) {
51 void test_j(int* ip
) {
60 #if __cplusplus <= 199711L
61 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
63 // expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
66 int* ip2
= k(("foo"));
67 #if __cplusplus <= 199711L
68 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
70 // expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
72 double* dp1
= k(L
"foo");
80 #if __cplusplus <= 199711L
81 // expected-warning@-2 {{conversion from string literal to 'wchar_t *' is deprecated}}
83 // expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
85 double* dp1
= l("foo");
103 #if __cplusplus <= 199711L
104 // expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
106 // expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}}
115 PromotesToIntValue
= -1
118 enum PromotesToUnsignedInt
{
119 PromotesToUnsignedIntValue
= __INT_MAX__
* 2U
123 double* o(unsigned int);
127 int* ip1
= o(PromotesToIntValue
);
128 double* dp1
= o(PromotesToUnsignedIntValue
);
135 int* ip
= p((short)1);
136 double* dp
= p(1.0f
);
140 signed short int_bitfield
: 5;
141 unsigned int uint_bitfield
: 8;
144 int* bitfields(int, int);
145 float* bitfields(unsigned int, int);
147 void test_bitfield(Bits bits
, int x
) {
148 int* ip
= bitfields(bits
.int_bitfield
, 0);
149 float* fp
= bitfields(bits
.uint_bitfield
, 0u);
152 int* multiparm(long, int, long); // expected-note {{candidate function}}
153 float* multiparm(int, int, int); // expected-note {{candidate function}}
154 double* multiparm(int, int, short); // expected-note {{candidate function}}
156 void test_multiparm(long lv
, short sv
, int iv
) {
157 int* ip1
= multiparm(lv
, iv
, lv
);
158 int* ip2
= multiparm(lv
, sv
, lv
);
159 float* fp1
= multiparm(iv
, iv
, iv
);
160 float* fp2
= multiparm(sv
, iv
, iv
);
161 double* dp1
= multiparm(sv
, sv
, sv
);
162 double* dp2
= multiparm(iv
, sv
, sv
);
163 multiparm(sv
, sv
, lv
); // expected-error {{call to 'multiparm' is ambiguous}}
166 // Test overloading based on qualification vs. no qualification
168 int* quals1(int const * p
);
169 char* quals1(int * p
);
171 int* quals2(int const * const * pp
);
172 char* quals2(int * * pp
);
174 int* quals3(int const * * const * ppp
);
175 char* quals3(int *** ppp
);
177 void test_quals(int * p
, int * * pp
, int * * * ppp
) {
178 char* q1
= quals1(p
);
179 char* q2
= quals2(pp
);
180 char* q3
= quals3(ppp
);
183 // Test overloading based on qualification ranking (C++ 13.3.2)p3.
184 int* quals_rank1(int const * p
);
185 float* quals_rank1(int const volatile *p
);
186 char* quals_rank1(char*);
187 double* quals_rank1(const char*);
189 int* quals_rank2(int const * const * pp
);
190 float* quals_rank2(int * const * pp
);
192 void quals_rank3(int const * const * const volatile * p
); // expected-note{{candidate function}}
193 void quals_rank3(int const * const volatile * const * p
); // expected-note{{candidate function}}
195 void quals_rank3(int const *); // expected-note{{candidate function}}
196 void quals_rank3(int volatile *); // expected-note{{candidate function}}
198 void test_quals_ranking(int * p
, int volatile *pq
, int * * pp
, int * * * ppp
) {
199 int* q1
= quals_rank1(p
);
200 float* q2
= quals_rank1(pq
);
201 double* q3
= quals_rank1("string literal");
204 char* q4
= quals_rank1(a
);
205 double* q5
= quals_rank1(ap
);
207 float* q6
= quals_rank2(pp
);
209 quals_rank3(ppp
); // expected-error {{call to 'quals_rank3' is ambiguous}}
211 quals_rank3(p
); // expected-error {{call to 'quals_rank3' is ambiguous}}
215 // Test overloading based on derived-to-base conversions
217 class B
: public A
{ };
218 class C
: public B
{ };
219 class D
: public C
{ };
222 char* derived1(const A
*);
223 float* derived1(void*);
229 float* derived3(const B
*);
232 void test_derived(B
* b
, B
const* bc
, C
* c
, const C
* cc
, void* v
, D
* d
) {
233 int* d1
= derived1(b
);
234 char* d2
= derived1(bc
);
235 int* d3
= derived1(c
);
236 char* d4
= derived1(cc
);
237 float* d5
= derived1(v
);
239 float* d6
= derived2(b
);
240 float* d7
= derived2(c
);
242 char* d8
= derived3(d
);
245 void derived4(C
*); // expected-note{{candidate function not viable: cannot convert from base class pointer 'A *' to derived class pointer 'C *' for 1st argument}}
247 void test_base(A
* a
) {
248 derived4(a
); // expected-error{{no matching function for call to 'derived4}}
251 // Test overloading of references.
252 // (FIXME: tests binding to determine candidate sets, not overload
253 // resolution per se).
255 float* intref(const int&);
258 float* ir1
= intref(5);
259 float* ir2
= intref(5.5); // expected-warning{{implicit conversion from 'double' to 'int' changes value from 5.5 to 5}}
262 void derived5(C
&); // expected-note{{candidate function not viable: cannot bind base class object of type 'A' to derived class reference 'C &' for 1st argument}}
264 void test_base(A
& a
) {
265 derived5(a
); // expected-error{{no matching function for call to 'derived5}}
268 // Test reference binding vs. standard conversions.
269 int& bind_vs_conv(const double&);
270 float& bind_vs_conv(int);
272 void bind_vs_conv_test()
274 int& i1
= bind_vs_conv(1.0f
);
275 float& f1
= bind_vs_conv((short)1);
278 // Test that cv-qualifiers get subsumed in the reference binding.
283 int& cvqual_subsume(X
&); // expected-note{{candidate function}}
284 float& cvqual_subsume(const Y
&); // expected-note{{candidate function}}
286 int& cvqual_subsume2(X
&); // expected-note{{candidate function}}
287 float& cvqual_subsume2(volatile Y
&); // expected-note{{candidate function}}
289 void cvqual_subsume_test(Z z
) {
290 cvqual_subsume(z
); // expected-error{{call to 'cvqual_subsume' is ambiguous}}
291 cvqual_subsume2(z
); // expected-error{{call to 'cvqual_subsume2' is ambiguous}}
294 // Test overloading with cv-qualification differences in reference
296 int& cvqual_diff(X
&);
297 float& cvqual_diff(const X
&);
299 void cvqual_diff_test(X x
, Z z
) {
300 int& i1
= cvqual_diff(x
);
301 int& i2
= cvqual_diff(z
);
304 // Test overloading with derived-to-base differences in reference
310 float& db_rebind(Z
&);
312 void db_rebind_test(Z2 z2
) {
313 float& f1
= db_rebind(z2
);
317 class opt
: public string
{ };
332 float &a(void*, float);
339 // Tests the exact text used to note the candidates
342 void foo(T t
, unsigned N
); // expected-note {{candidate function template not viable: no known conversion from 'const char[6]' to 'unsigned int' for 2nd argument}}
343 void foo(int n
, char N
); // expected-note {{candidate function not viable: no known conversion from 'const char[6]' to 'char' for 2nd argument}}
344 void foo(int n
, const char *s
, int t
); // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
345 void foo(int n
, const char *s
, int t
, ...); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
346 void foo(int n
, const char *s
, int t
, int u
= 0); // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
349 void foo(int n
); // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
350 void foo(unsigned n
= 10); // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
351 void bar(int n
, int u
= 0); // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
352 void baz(int n
= 0, int u
= 0); // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
355 foo(4, "hello"); //expected-error {{no matching function for call to 'foo'}}
356 bar(); //expected-error {{no matching function for call to 'bar'}}
357 baz(3, 4, 5); // expected-error {{no matching function for call to 'baz'}}
368 bool operator==(const QFixed
&f
, int i
);
371 inline operator unsigned int () const;
373 inline bool operator==(const qrgb666
&v
) const;
374 inline bool operator!=(const qrgb666
&v
) const { return !(*this == v
); }
379 namespace IncompleteConversion
{
383 void completeFunction(Complete
*); // expected-note 2 {{cannot convert argument of incomplete type}}
384 void completeFunction(Complete
&); // expected-note 2 {{cannot convert argument of incomplete type}}
386 void testTypeConversion(Incomplete
*P
) {
387 completeFunction(P
); // expected-error {{no matching function for call to 'completeFunction'}}
388 completeFunction(*P
); // expected-error {{no matching function for call to 'completeFunction'}}
391 void incompletePointerFunction(Incomplete
*); // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'Incomplete' to 'Incomplete *' for 1st argument; take the address of the argument with &}}
392 void incompleteReferenceFunction(Incomplete
&); // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'Incomplete *' to 'Incomplete &' for 1st argument; dereference the argument with *}}
394 void testPointerReferenceConversion(Incomplete
&reference
, Incomplete
*pointer
) {
395 incompletePointerFunction(reference
); // expected-error {{no matching function for call to 'incompletePointerFunction'}}
396 incompleteReferenceFunction(pointer
); // expected-error {{no matching function for call to 'incompleteReferenceFunction'}}
400 namespace DerivedToBaseVsVoid
{
416 static void foo(); // expected-note {{not viable}}
417 static void foo(int*); // expected-note {{not viable}}
418 static void foo(long*); // expected-note {{not viable}}
421 foo(a
); // expected-error {{no matching function for call}}
426 namespace DerivedToBase
{
441 operator const unsigned int & () const;
445 operator unsigned int & () const;
448 void f0(const bool &);
449 void f1(bool &); // expected-note 2{{not viable}}
451 void g(X0 x0
, X1 x1
) {
453 f1(x0
); // expected-error{{no matching function for call}}
455 f1(x1
); // expected-error{{no matching function for call}}
461 A(short); // expected-note{{candidate constructor}}
462 A(long); // expected-note{{candidate constructor}}
470 S()(0); // expected-error{{conversion from 'int' to 'A' is ambiguous}}
475 struct String
{ String(char const*); };
477 void f(bool const volatile&);
480 void g() { int &r
= f(""); }
494 void g(Y y
) { f(y
); }
499 class B
: public A
{};
501 int &foo(A
*const d
);
502 float &foo(const A
*const d
);
507 B
const *const d2
= 0;
513 namespace NontrivialSubsequence
{
519 operator const X0
*();
523 void foo( void const * );
530 // rdar://rdar8499524
531 namespace rdar8499524
{
543 namespace rdar9173984
{
544 template <typename T
, unsigned long N
> int &f(const T (&)[N
]);
545 template <typename T
> float &f(const T
*);
556 void f(int * const&); // expected-note{{candidate function}}
557 void f(int const(&)[1]); // expected-note{{candidate function}}
561 f(n
); // expected-error{{call to 'f' is ambiguous}}
565 namespace rdar9803316
{
574 namespace IncompleteArg
{
575 // Ensure that overload resolution attempts to complete argument types when
577 template<typename T
> struct S
{
578 friend int f(const S
&);
583 template<typename T
> struct Op
{
584 friend bool operator==(const Op
&, const Op
&);
589 // ... and not in other cases! Nothing here requires U<int()> to be complete.
590 // (Note that instantiating U<int()> will fail.)
591 template<typename T
> struct U
{
596 int operator()(const U
<T
> &);
598 template<typename T
> U
<T
> &make();
600 int n
= sizeof(c(make
<int()>()));
604 void fun(int (*x
)[10]); // expected-note{{candidate function not viable: 1st argument ('const int (*)[10]') would lose const qualifier}}
605 void g() { fun((const int(*)[10])0); } // expected-error{{no matching function for call to 'fun'}}
608 // DR1152: Take 'volatile' into account when handling reference bindings in
609 // overload resolution.
611 void f(const int &, ...);
612 void f(const volatile int &, int);
613 void g() { f(0, 0); }
618 typedef void F1(int);
619 typedef void F2(double);
620 operator F1
*(); // expected-note{{conversion candidate}}
621 operator F2
*(); // expected-note{{conversion candidate}}
623 callable(); // expected-error{{no matching function for call}}
627 void f(void (*const &)()); // expected-note 2{{candidate}}
628 void f(void (&&)()) = delete; // expected-note 2{{candidate}}
629 #if __cplusplus <= 199711L
630 // expected-warning@-2 {{rvalue references are a C++11 extension}}
631 // expected-warning@-3 {{deleted function definitions are a C++11 extension}}
633 void g(void (&&)()) = delete; // expected-note 2{{candidate}}
634 #if __cplusplus <= 199711L
635 // expected-warning@-2 {{rvalue references are a C++11 extension}}
636 // expected-warning@-3 {{deleted function definitions are a C++11 extension}}
638 void g(void (*const &)()); // expected-note 2{{candidate}}
641 typedef void (&fr
)();
642 struct Y
{ operator fr(); } y
;
645 f(x
); // expected-error {{ambiguous}}
646 g(x
); // expected-error {{ambiguous}}
647 f(y
); // expected-error {{ambiguous}}
648 g(y
); // expected-error {{ambiguous}}
652 namespace StringLiteralToCharAmbiguity
{
654 void f(const char *, unsigned);
655 void g() { f("foo", 0); }
656 #if __cplusplus <= 199711L
657 // expected-error@-2 {{call to 'f' is ambiguous}}
658 // expected-note@-5 {{candidate function}}
659 // expected-note@-5 {{candidate function}}
663 namespace ProduceNotesAfterSFINAEFailure
{
665 template<typename T
, typename U
= typename
T::x
> A(T
); // expected-warning 0-1{{extension}}
667 void f(void*, A
); // expected-note {{candidate function not viable}}
668 void g() { f(1, 2); } // expected-error {{no matching function}}
676 struct D
: public B
{};
680 void f(void (D::*)());
686 // These should not be ambiguous.