2015-10-08 16:28:09 +08:00
// RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify %s
2015-12-10 09:07:17 +08:00
// RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify -std=c++98 %s
// RUN: %clang_cc1 -triple %itanium_abi_triple -pedantic -verify -std=c++11 %s
2008-10-29 23:10:40 +08:00
int * f ( int ) { return 0 ; }
float * f ( float ) { return 0 ; }
2008-10-22 00:13:35 +08:00
void f ( ) ;
void test_f ( int iv , float fv ) {
float * fp = f ( fv ) ;
int * ip = f ( iv ) ;
}
2011-12-15 08:38:15 +08:00
int * g ( int , float , int ) ; // expected-note {{candidate function}}
float * g ( int , int , int ) ; // expected-note {{candidate function}}
double * g ( int , float , float ) ; // expected-note {{candidate function}}
char * g ( int , float , . . . ) ; // expected-note {{candidate function}}
2008-10-22 00:13:35 +08:00
void g ( ) ;
void test_g ( int iv , float fv ) {
int * ip1 = g ( iv , fv , 0 ) ;
float * fp1 = g ( iv , iv , 0 ) ;
double * dp1 = g ( iv , fv , fv ) ;
char * cp1 = g ( 0 , 0 ) ;
char * cp2 = g ( 0 , 0 , 0 , iv , fv ) ;
2011-12-15 08:38:15 +08:00
double * dp2 = g ( 0 , fv , 1.5 ) ; // expected-error {{call to 'g' is ambiguous}}
2008-10-22 00:13:35 +08:00
}
double * h ( double f ) ;
int * h ( int ) ;
void test_h ( float fv , unsigned char cv ) {
double * dp = h ( fv ) ;
int * ip = h ( cv ) ;
}
int * i ( int ) ;
double * i ( long ) ;
void test_i ( short sv , int iv , long lv , unsigned char ucv ) {
int * ip1 = i ( sv ) ;
int * ip2 = i ( iv ) ;
int * ip3 = i ( ucv ) ;
double * dp1 = i ( lv ) ;
}
int * j ( void * ) ;
double * j ( bool ) ;
void test_j ( int * ip ) {
int * ip1 = j ( ip ) ;
}
int * k ( char * ) ;
double * k ( bool ) ;
void test_k ( ) {
2015-12-10 09:07:17 +08:00
int * ip1 = k ( " foo " ) ;
# if __cplusplus <= 199711L
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
# else
// expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
# endif
int * ip2 = k ( ( " foo " ) ) ;
# if __cplusplus <= 199711L
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
# else
// expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
# endif
2008-10-22 00:13:35 +08:00
double * dp1 = k ( L " foo " ) ;
}
int * l ( wchar_t * ) ;
double * l ( bool ) ;
void test_l ( ) {
2015-12-10 09:07:17 +08:00
int * ip1 = l ( L " foo " ) ;
# if __cplusplus <= 199711L
// expected-warning@-2 {{conversion from string literal to 'wchar_t *' is deprecated}}
# else
// expected-error@-4 {{cannot initialize a variable of type 'int *' with an rvalue of type 'double *'}}
# endif
2008-10-22 00:13:35 +08:00
double * dp1 = l ( " foo " ) ;
}
int * m ( const char * ) ;
double * m ( char * ) ;
void test_m ( ) {
int * ip = m ( " foo " ) ;
}
int * n ( char * ) ;
double * n ( void * ) ;
2008-11-27 07:33:36 +08:00
class E ;
2008-10-22 00:13:35 +08:00
2008-11-27 07:33:36 +08:00
void test_n ( E * e ) {
2008-10-22 00:13:35 +08:00
char ca [ 7 ] ;
int * ip1 = n ( ca ) ;
2015-12-10 09:07:17 +08:00
int * ip2 = n ( " foo " ) ;
# if __cplusplus <= 199711L
// expected-warning@-2 {{conversion from string literal to 'char *' is deprecated}}
# else
// expected-warning@-4 {{ISO C++11 does not allow conversion from string literal to 'char *'}}
# endif
2008-10-22 00:13:35 +08:00
float fa [ 7 ] ;
double * dp1 = n ( fa ) ;
2008-11-27 07:33:36 +08:00
double * dp2 = n ( e ) ;
2008-10-22 00:13:35 +08:00
}
enum PromotesToInt {
2008-12-12 10:00:36 +08:00
PromotesToIntValue = - 1
2008-10-22 00:13:35 +08:00
} ;
enum PromotesToUnsignedInt {
2009-12-09 17:09:27 +08:00
PromotesToUnsignedIntValue = __INT_MAX__ * 2U
2008-10-22 00:13:35 +08:00
} ;
int * o ( int ) ;
double * o ( unsigned int ) ;
float * o ( long ) ;
void test_o ( ) {
int * ip1 = o ( PromotesToIntValue ) ;
double * dp1 = o ( PromotesToUnsignedIntValue ) ;
}
int * p ( int ) ;
double * p ( double ) ;
void test_p ( ) {
int * ip = p ( ( short ) 1 ) ;
double * dp = p ( 1.0f ) ;
}
struct Bits {
signed short int_bitfield : 5 ;
unsigned int uint_bitfield : 8 ;
} ;
int * bitfields ( int , int ) ;
float * bitfields ( unsigned int , int ) ;
void test_bitfield ( Bits bits , int x ) {
int * ip = bitfields ( bits . int_bitfield , 0 ) ;
float * fp = bitfields ( bits . uint_bitfield , 0u ) ;
}
2011-12-15 08:38:15 +08:00
int * multiparm ( long , int , long ) ; // expected-note {{candidate function}}
float * multiparm ( int , int , int ) ; // expected-note {{candidate function}}
double * multiparm ( int , int , short ) ; // expected-note {{candidate function}}
2008-10-22 00:13:35 +08:00
void test_multiparm ( long lv , short sv , int iv ) {
int * ip1 = multiparm ( lv , iv , lv ) ;
int * ip2 = multiparm ( lv , sv , lv ) ;
float * fp1 = multiparm ( iv , iv , iv ) ;
float * fp2 = multiparm ( sv , iv , iv ) ;
double * dp1 = multiparm ( sv , sv , sv ) ;
double * dp2 = multiparm ( iv , sv , sv ) ;
2011-12-15 08:38:15 +08:00
multiparm ( sv , sv , lv ) ; // expected-error {{call to 'multiparm' is ambiguous}}
2008-10-22 00:13:35 +08:00
}
2008-10-22 08:38:21 +08:00
// Test overloading based on qualification vs. no qualification
// conversion.
int * quals1 ( int const * p ) ;
char * quals1 ( int * p ) ;
int * quals2 ( int const * const * pp ) ;
char * quals2 ( int * * pp ) ;
int * quals3 ( int const * * const * ppp ) ;
char * quals3 ( int * * * ppp ) ;
void test_quals ( int * p , int * * pp , int * * * ppp ) {
char * q1 = quals1 ( p ) ;
char * q2 = quals2 ( pp ) ;
char * q3 = quals3 ( ppp ) ;
}
// Test overloading based on qualification ranking (C++ 13.3.2)p3.
int * quals_rank1 ( int const * p ) ;
float * quals_rank1 ( int const volatile * p ) ;
2008-10-22 22:17:15 +08:00
char * quals_rank1 ( char * ) ;
double * quals_rank1 ( const char * ) ;
2008-10-22 08:38:21 +08:00
int * quals_rank2 ( int const * const * pp ) ;
float * quals_rank2 ( int * const * pp ) ;
2008-10-22 22:17:15 +08:00
void quals_rank3 ( int const * const * const volatile * p ) ; // expected-note{{candidate function}}
void quals_rank3 ( int const * const volatile * const * p ) ; // expected-note{{candidate function}}
void quals_rank3 ( int const * ) ; // expected-note{{candidate function}}
void quals_rank3 ( int volatile * ) ; // expected-note{{candidate function}}
2008-10-22 08:38:21 +08:00
void test_quals_ranking ( int * p , int volatile * pq , int * * pp , int * * * ppp ) {
2008-10-22 22:17:15 +08:00
int * q1 = quals_rank1 ( p ) ;
2008-10-22 08:38:21 +08:00
float * q2 = quals_rank1 ( pq ) ;
2008-10-22 22:17:15 +08:00
double * q3 = quals_rank1 ( " string literal " ) ;
char a [ 17 ] ;
const char * ap = a ;
char * q4 = quals_rank1 ( a ) ;
double * q5 = quals_rank1 ( ap ) ;
float * q6 = quals_rank2 ( pp ) ;
2011-12-15 08:38:15 +08:00
quals_rank3 ( ppp ) ; // expected-error {{call to 'quals_rank3' is ambiguous}}
2008-10-22 22:17:15 +08:00
2011-12-15 08:38:15 +08:00
quals_rank3 ( p ) ; // expected-error {{call to 'quals_rank3' is ambiguous}}
2008-10-22 22:17:15 +08:00
quals_rank3 ( pq ) ;
2008-10-22 08:38:21 +08:00
}
2008-10-22 22:17:15 +08:00
2008-10-23 08:40:37 +08:00
// Test overloading based on derived-to-base conversions
class A { } ;
class B : public A { } ;
class C : public B { } ;
class D : public C { } ;
int * derived1 ( A * ) ;
char * derived1 ( const A * ) ;
float * derived1 ( void * ) ;
int * derived2 ( A * ) ;
float * derived2 ( B * ) ;
int * derived3 ( A * ) ;
float * derived3 ( const B * ) ;
char * derived3 ( C * ) ;
void test_derived ( B * b , B const * bc , C * c , const C * cc , void * v , D * d ) {
int * d1 = derived1 ( b ) ;
char * d2 = derived1 ( bc ) ;
int * d3 = derived1 ( c ) ;
char * d4 = derived1 ( cc ) ;
float * d5 = derived1 ( v ) ;
float * d6 = derived2 ( b ) ;
float * d7 = derived2 ( c ) ;
char * d8 = derived3 ( d ) ;
}
2008-10-29 08:13:59 +08:00
2010-07-01 07:01:39 +08:00
void derived4 ( C * ) ; // expected-note{{candidate function not viable: cannot convert from base class pointer 'A *' to derived class pointer 'C *' for 1st argument}}
void test_base ( A * a ) {
derived4 ( a ) ; // expected-error{{no matching function for call to 'derived4}}
}
2008-10-29 08:13:59 +08:00
// Test overloading of references.
// (FIXME: tests binding to determine candidate sets, not overload
// resolution per se).
int * intref ( int & ) ;
float * intref ( const int & ) ;
void intref_test ( ) {
float * ir1 = intref ( 5 ) ;
2012-05-16 00:56:36 +08:00
float * ir2 = intref ( 5.5 ) ; // expected-warning{{implicit conversion from 'double' to 'int' changes value from 5.5 to 5}}
2008-10-29 08:13:59 +08:00
}
2008-10-29 10:00:59 +08:00
2010-07-01 10:14:45 +08:00
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}}
void test_base ( A & a ) {
derived5 ( a ) ; // expected-error{{no matching function for call to 'derived5}}
}
2008-10-29 10:00:59 +08:00
// Test reference binding vs. standard conversions.
int & bind_vs_conv ( const double & ) ;
float & bind_vs_conv ( int ) ;
void bind_vs_conv_test ( )
{
int & i1 = bind_vs_conv ( 1.0f ) ;
float & f1 = bind_vs_conv ( ( short ) 1 ) ;
}
// Test that cv-qualifiers get subsumed in the reference binding.
struct X { } ;
struct Y { } ;
struct Z : X , Y { } ;
int & cvqual_subsume ( X & ) ; // expected-note{{candidate function}}
float & cvqual_subsume ( const Y & ) ; // expected-note{{candidate function}}
2012-05-24 12:29:20 +08:00
int & cvqual_subsume2 ( X & ) ; // expected-note{{candidate function}}
float & cvqual_subsume2 ( volatile Y & ) ; // expected-note{{candidate function}}
2008-10-29 10:00:59 +08:00
void cvqual_subsume_test ( Z z ) {
2011-12-15 08:38:15 +08:00
cvqual_subsume ( z ) ; // expected-error{{call to 'cvqual_subsume' is ambiguous}}
2012-05-24 12:29:20 +08:00
cvqual_subsume2 ( z ) ; // expected-error{{call to 'cvqual_subsume2' is ambiguous}}
2008-10-29 10:00:59 +08:00
}
2008-10-29 22:50:44 +08:00
// Test overloading with cv-qualification differences in reference
// binding.
int & cvqual_diff ( X & ) ;
float & cvqual_diff ( const X & ) ;
void cvqual_diff_test ( X x , Z z ) {
int & i1 = cvqual_diff ( x ) ;
int & i2 = cvqual_diff ( z ) ;
}
// Test overloading with derived-to-base differences in reference
// binding.
struct Z2 : Z { } ;
int & db_rebind ( X & ) ;
long & db_rebind ( Y & ) ;
float & db_rebind ( Z & ) ;
void db_rebind_test ( Z2 z2 ) {
float & f1 = db_rebind ( z2 ) ;
}
2009-11-06 09:02:41 +08:00
class string { } ;
class opt : public string { } ;
struct SR {
SR ( const string & ) ;
} ;
void f ( SR ) { }
void g ( opt o ) {
f ( o ) ;
}
2009-12-14 05:29:20 +08:00
namespace PR5756 {
int & a ( void * , int ) ;
float & a ( void * , float ) ;
void b ( ) {
int & ir = a ( 0 , 0 ) ;
( void ) ir ;
}
}
2010-01-12 10:15:36 +08:00
// Tests the exact text used to note the candidates
namespace test1 {
2018-05-30 09:00:41 +08:00
template < class T >
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}}
void foo ( int n , char N ) ; // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
void foo ( int n , const char * s , int t ) ; // expected-note {{candidate function not viable: requires 3 arguments, but 2 were provided}}
void foo ( int n , const char * s , int t , . . . ) ; // expected-note {{candidate function not viable: requires at least 3 arguments, but 2 were provided}}
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}}
// PR 11857
void foo ( int n ) ; // expected-note {{candidate function not viable: requires single argument 'n', but 2 arguments were provided}}
void foo ( unsigned n = 10 ) ; // expected-note {{candidate function not viable: allows at most single argument 'n', but 2 arguments were provided}}
void bar ( int n , int u = 0 ) ; // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
void baz ( int n = 0 , int u = 0 ) ; // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
void test ( ) {
foo ( 4 , " hello " ) ; //expected-error {{no matching function for call to 'foo'}}
bar ( ) ; //expected-error {{no matching function for call to 'bar'}}
baz ( 3 , 4 , 5 ) ; // expected-error {{no matching function for call to 'baz'}}
2010-01-12 10:15:36 +08:00
}
}
2010-01-13 17:16:55 +08:00
2010-01-14 06:30:33 +08:00
// PR 6014
namespace test2 {
struct QFixed {
QFixed ( int i ) ;
QFixed ( long i ) ;
} ;
bool operator = = ( const QFixed & f , int i ) ;
class qrgb666 {
inline operator unsigned int ( ) const ;
inline bool operator = = ( const qrgb666 & v ) const ;
inline bool operator ! = ( const qrgb666 & v ) const { return ! ( * this = = v ) ; }
} ;
}
2010-01-23 16:10:49 +08:00
// PR 6117
2016-03-05 06:29:11 +08:00
namespace IncompleteConversion {
struct Complete { } ;
2010-01-23 16:10:49 +08:00
struct Incomplete ;
2016-03-05 06:29:11 +08:00
void completeFunction ( Complete * ) ; // expected-note 2 {{cannot convert argument of incomplete type}}
void completeFunction ( Complete & ) ; // expected-note 2 {{cannot convert argument of incomplete type}}
void testTypeConversion ( Incomplete * P ) {
completeFunction ( P ) ; // expected-error {{no matching function for call to 'completeFunction'}}
completeFunction ( * P ) ; // expected-error {{no matching function for call to 'completeFunction'}}
}
void incompletePointerFunction ( Incomplete * ) ; // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'IncompleteConversion::Incomplete' to 'IncompleteConversion::Incomplete *' for 1st argument; take the address of the argument with &}}
void incompleteReferenceFunction ( Incomplete & ) ; // expected-note {{candidate function not viable: cannot convert argument of incomplete type 'IncompleteConversion::Incomplete *' to 'IncompleteConversion::Incomplete &' for 1st argument; dereference the argument with *}}
void testPointerReferenceConversion ( Incomplete & reference , Incomplete * pointer ) {
incompletePointerFunction ( reference ) ; // expected-error {{no matching function for call to 'incompletePointerFunction'}}
incompleteReferenceFunction ( pointer ) ; // expected-error {{no matching function for call to 'incompleteReferenceFunction'}}
2010-01-23 16:10:49 +08:00
}
}
2010-01-27 11:51:04 +08:00
namespace DerivedToBaseVsVoid {
struct A { } ;
struct B : A { } ;
float & f ( void * ) ;
int & f ( const A * ) ;
void g ( B * b ) {
int & ir = f ( b ) ;
}
}
2010-02-25 09:37:24 +08:00
2010-02-25 18:46:05 +08:00
// PR 6398 + PR 6421
2010-02-25 09:37:24 +08:00
namespace test4 {
class A ;
class B {
static void foo ( ) ; // expected-note {{not viable}}
static void foo ( int * ) ; // expected-note {{not viable}}
2010-02-25 18:46:05 +08:00
static void foo ( long * ) ; // expected-note {{not viable}}
2010-02-25 09:37:24 +08:00
void bar ( A * a ) {
foo ( a ) ; // expected-error {{no matching function for call}}
}
} ;
}
2010-02-26 03:01:05 +08:00
namespace DerivedToBase {
struct A { } ;
struct B : A { } ;
struct C : B { } ;
int & f0 ( const A & ) ;
float & f0 ( B ) ;
void g ( ) {
float & fr = f0 ( C ( ) ) ;
}
}
2010-03-08 07:17:44 +08:00
namespace PR6483 {
struct X0 {
operator const unsigned int & ( ) const ;
} ;
struct X1 {
operator unsigned int & ( ) const ;
} ;
void f0 ( const bool & ) ;
void f1 ( bool & ) ; // expected-note 2{{not viable}}
void g ( X0 x0 , X1 x1 ) {
f0 ( x0 ) ;
f1 ( x0 ) ; // expected-error{{no matching function for call}}
f0 ( x1 ) ;
f1 ( x1 ) ; // expected-error{{no matching function for call}}
}
}
2010-04-13 23:50:39 +08:00
namespace PR6078 {
2010-04-25 04:54:38 +08:00
struct A {
2010-04-13 23:50:39 +08:00
A ( short ) ; // expected-note{{candidate constructor}}
A ( long ) ; // expected-note{{candidate constructor}}
} ;
struct S {
typedef void ft ( A ) ;
operator ft * ( ) ;
} ;
void f ( ) {
S ( ) ( 0 ) ; // expected-error{{conversion from 'int' to 'PR6078::A' is ambiguous}}
}
}
2010-04-18 17:22:00 +08:00
namespace PR6177 {
struct String { String ( char const * ) ; } ;
2012-05-24 12:29:20 +08:00
void f ( bool const volatile & ) ;
int & f ( String ) ;
2010-04-18 17:22:00 +08:00
2012-05-24 12:29:20 +08:00
void g ( ) { int & r = f ( " " ) ; }
2010-04-18 17:22:00 +08:00
}
2010-05-24 06:10:15 +08:00
namespace PR7095 {
struct X { } ;
struct Y {
operator const X * ( ) ;
private :
operator X * ( ) ;
} ;
void f ( const X * ) ;
void g ( Y y ) { f ( y ) ; }
}
2010-05-25 23:31:05 +08:00
namespace PR7224 {
class A { } ;
class B : public A { } ;
int & foo ( A * const d ) ;
float & foo ( const A * const d ) ;
void bar ( )
{
B * const d = 0 ;
B const * const d2 = 0 ;
int & ir = foo ( d ) ;
float & fr = foo ( d2 ) ;
}
}
2010-06-09 11:53:18 +08:00
namespace NontrivialSubsequence {
struct X0 ;
class A {
operator X0 * ( ) ;
public :
operator const X0 * ( ) ;
} ;
A a ;
void foo ( void const * ) ;
void g ( ) {
foo ( a ) ;
}
}
2010-10-05 11:15:43 +08:00
// rdar://rdar8499524
namespace rdar8499524 {
struct W { } ;
struct S {
S ( . . . ) ;
} ;
void g ( const S & ) ;
void f ( ) {
g ( W ( ) ) ;
}
}
2011-06-05 14:15:20 +08:00
namespace rdar9173984 {
template < typename T , unsigned long N > int & f ( const T ( & ) [ N ] ) ;
template < typename T > float & f ( const T * ) ;
void test ( ) {
int arr [ 2 ] = { 0 , 0 } ;
int * arrp = arr ;
int & ir = f ( arr ) ;
float & fr = f ( arrp ) ;
}
}
namespace PR9507 {
void f ( int * const & ) ; // expected-note{{candidate function}}
void f ( int const ( & ) [ 1 ] ) ; // expected-note{{candidate function}}
int main ( ) {
int n [ 1 ] ;
f ( n ) ; // expected-error{{call to 'f' is ambiguous}}
}
}
2011-10-14 02:10:35 +08:00
namespace rdar9803316 {
void foo ( float ) ;
int & foo ( int ) ;
void bar ( ) {
int & ir = ( & foo ) ( 0 ) ;
}
}
2012-02-22 10:04:18 +08:00
namespace IncompleteArg {
2012-02-25 14:24:24 +08:00
// Ensure that overload resolution attempts to complete argument types when
// performing ADL.
2012-02-22 10:04:18 +08:00
template < typename T > struct S {
friend int f ( const S & ) ;
} ;
extern S < int > s ;
int k = f ( s ) ;
2012-02-25 14:24:24 +08:00
template < typename T > struct Op {
friend bool operator = = ( const Op & , const Op & ) ;
} ;
extern Op < char > op ;
bool b = op = = op ;
// ... and not in other cases! Nothing here requires U<int()> to be complete.
// (Note that instantiating U<int()> will fail.)
template < typename T > struct U {
T t ;
} ;
struct Consumer {
template < typename T >
int operator ( ) ( const U < T > & ) ;
} ;
template < typename T > U < T > & make ( ) ;
Consumer c ;
int n = sizeof ( c ( make < int ( ) > ( ) ) ) ;
2012-02-22 10:04:18 +08:00
}
2012-03-10 08:29:33 +08:00
namespace PR12142 {
void fun ( int ( * x ) [ 10 ] ) ; // expected-note{{candidate function not viable: 1st argument ('const int (*)[10]') would lose const qualifier}}
void g ( ) { fun ( ( const int ( * ) [ 10 ] ) 0 ) ; } // expected-error{{no matching function for call to 'fun'}}
}
2012-05-24 12:29:20 +08:00
// DR1152: Take 'volatile' into account when handling reference bindings in
// overload resolution.
namespace PR12931 {
void f ( const int & , . . . ) ;
void f ( const volatile int & , int ) ;
void g ( ) { f ( 0 , 0 ) ; }
}
2014-05-07 06:28:58 +08:00
void test5 ( ) {
struct {
typedef void F1 ( int ) ;
typedef void F2 ( double ) ;
operator F1 * ( ) ; // expected-note{{conversion candidate}}
operator F2 * ( ) ; // expected-note{{conversion candidate}}
} callable ;
callable ( ) ; // expected-error{{no matching function for call}}
}
2014-07-14 10:28:44 +08:00
namespace PR20218 {
2014-07-15 03:54:05 +08:00
void f ( void ( * const & ) ( ) ) ; // expected-note 2{{candidate}}
2015-12-10 09:07:17 +08:00
void f ( void ( & & ) ( ) ) = delete ; // expected-note 2{{candidate}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{rvalue references are a C++11 extension}}
// expected-warning@-3 {{deleted function definitions are a C++11 extension}}
# endif
void g ( void ( & & ) ( ) ) = delete ; // expected-note 2{{candidate}}
# if __cplusplus <= 199711L
// expected-warning@-2 {{rvalue references are a C++11 extension}}
// expected-warning@-3 {{deleted function definitions are a C++11 extension}}
# endif
2014-07-15 03:54:05 +08:00
void g ( void ( * const & ) ( ) ) ; // expected-note 2{{candidate}}
2014-07-14 10:28:44 +08:00
void x ( ) ;
typedef void ( & fr ) ( ) ;
struct Y { operator fr ( ) ; } y ;
void h ( ) {
f ( x ) ; // expected-error {{ambiguous}}
g ( x ) ; // expected-error {{ambiguous}}
2014-07-15 03:54:05 +08:00
f ( y ) ; // expected-error {{ambiguous}}
g ( y ) ; // expected-error {{ambiguous}}
2014-07-14 10:28:44 +08:00
}
}
[Sema] Compare bad conversions in overload resolution.
r280553 introduced an issue where we'd emit ambiguity errors for code
like:
```
void foo(int *, int);
void foo(unsigned int *, unsigned int);
void callFoo() {
unsigned int i;
foo(&i, 0); // ambiguous: int->unsigned int is worse than int->int,
// but unsigned int*->unsigned int* is better than
// int*->int*.
}
```
This patch fixes this issue by changing how we handle ill-formed (but
valid) implicit conversions. Candidates with said conversions now always
rank worse than candidates without them, and two candidates are
considered to be equally bad if they both have these conversions for
the same argument.
Additionally, this fixes a case in C++11 where we'd complain about an
ambiguity in a case like:
```
void f(char *, int);
void f(const char *, unsigned);
void g() { f("abc", 0); }
```
...Since conversion to char* from a string literal is considered
ill-formed in C++11 (and deprecated in C++03), but we accept it as an
extension.
llvm-svn: 280847
2016-09-08 04:03:19 +08:00
namespace StringLiteralToCharAmbiguity {
void f ( char * , int ) ;
void f ( const char * , unsigned ) ;
void g ( ) { f ( " foo " , 0 ) ; }
# if __cplusplus <= 199711L
// expected-error@-2 {{call to 'f' is ambiguous}}
// expected-note@-5 {{candidate function}}
// expected-note@-5 {{candidate function}}
# endif
}
2017-11-30 16:18:21 +08:00
namespace ProduceNotesAfterSFINAEFailure {
struct A {
template < typename T , typename U = typename T : : x > A ( T ) ; // expected-warning 0-1{{extension}}
} ;
void f ( void * , A ) ; // expected-note {{candidate function not viable}}
void g ( ) { f ( 1 , 2 ) ; } // expected-error {{no matching function}}
}
Fix overload resolution between Ptr-To-Member and Bool
As reported here (https://bugs.llvm.org/show_bug.cgi?id=19808)
and discovered independently when looking at plum-hall tests,
we incorrectly implemented over.ics.rank, which says "A conversion
that is not a conversion of a pointer, or pointer to member, to bool
is better than another conversion that is such a conversion.".
In the current Draft (N4750), this is phrased slightly differently in
paragraph 4.1: A conversion that does not convert a pointer, a pointer
to member, or std::nullptr_t to bool is better than one that does.
The comment on isPointerConversionToBool (the changed function)
also confirms that this is the case (note outdated reference):
isPointerConversionToBool - Determines whether this conversion is
a conversion of a pointer or pointer-to-member to bool. This is
used as part of the ranking of standard conversion sequences
(C++ 13.3.3.2p4).
However, despite this comment, it didn't check isMemberPointerType
on the 'FromType', presumably incorrectly assuming that 'isPointerType'
matched it. This patch fixes this by adding isMemberPointerType to
this function. Additionally, member function pointers are just
MemberPointerTypes that point to functions insted of data, so that
is fixed in this patch as well.
llvm-svn: 334503
2018-06-12 21:59:32 +08:00
namespace PR19808 {
struct B {
int i ;
void bar ( ) ;
} ;
struct D : public B { } ;
void f ( bool ) ;
void f ( int D : : * ) ;
void f ( void ( D : : * ) ( ) ) ;
void Usage ( ) {
int B : : * pmem ;
void ( B : : * pmf ) ( ) ;
// These should not be ambiguous.
f ( pmem ) ;
f ( pmf ) ;
}
}