2009-12-16 04:14:24 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify %s
2008-12-22 13:46:06 +08:00
struct X {
2009-02-08 03:52:04 +08:00
int & f ( int ) const ; // expected-note 2 {{candidate function}}
float & f ( int ) ; // expected-note 2 {{candidate function}}
2008-12-22 13:46:06 +08:00
void test_f ( int x ) const {
int & i = f ( x ) ;
}
void test_f2 ( int x ) {
float & f2 = f ( x ) ;
}
2009-02-08 03:52:04 +08:00
int & g ( int ) const ; // expected-note 2 {{candidate function}}
float & g ( int ) ; // expected-note 2 {{candidate function}}
static double & g ( double ) ; // expected-note 2 {{candidate function}}
2008-12-22 13:46:06 +08:00
void h ( int ) ;
2009-01-13 07:20:38 +08:00
void test_member ( ) {
float & f1 = f ( 0 ) ;
float & f2 = g ( 0 ) ;
double & d1 = g ( 0.0 ) ;
}
void test_member_const ( ) const {
int & i1 = f ( 0 ) ;
int & i2 = g ( 0 ) ;
double & d1 = g ( 0.0 ) ;
}
static void test_member_static ( ) {
double & d1 = g ( 0.0 ) ;
2011-12-15 08:38:15 +08:00
g ( 0 ) ; // expected-error{{call to 'g' is ambiguous}}
2009-01-13 07:20:38 +08:00
}
2008-12-22 13:46:06 +08:00
} ;
void test ( X x , const X xc , X * xp , const X * xcp , volatile X xv , volatile X * xvp ) {
int & i1 = xc . f ( 0 ) ;
int & i2 = xcp - > f ( 0 ) ;
float & f1 = x . f ( 0 ) ;
float & f2 = xp - > f ( 0 ) ;
2011-12-15 08:38:15 +08:00
xv . f ( 0 ) ; // expected-error{{no matching member function for call to 'f'}}
xvp - > f ( 0 ) ; // expected-error{{no matching member function for call to 'f'}}
2008-12-22 13:46:06 +08:00
int & i3 = xc . g ( 0 ) ;
int & i4 = xcp - > g ( 0 ) ;
float & f3 = x . g ( 0 ) ;
float & f4 = xp - > g ( 0 ) ;
double & d1 = xp - > g ( 0.0 ) ;
double & d2 = X : : g ( 0.0 ) ;
2011-12-15 08:38:15 +08:00
X : : g ( 0 ) ; // expected-error{{call to 'g' is ambiguous}}
2008-12-22 13:46:06 +08:00
X : : h ( 0 ) ; // expected-error{{call to non-static member function without an object argument}}
}
2009-11-05 08:07:36 +08:00
struct X1 {
int & member ( ) ;
float & member ( ) const ;
} ;
struct X2 : X1 { } ;
void test_X2 ( X2 * x2p , const X2 * cx2p ) {
int & ir = x2p - > member ( ) ;
float & fr = cx2p - > member ( ) ;
}
2010-01-13 17:16:55 +08:00
// Tests the exact text used to note the candidates
namespace test1 {
class A {
2017-01-09 16:01:21 +08:00
template < class T > void foo ( T t , unsigned N ) ; // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'unsigned int' for 2nd argument}}
2010-09-05 08:04:01 +08:00
void foo ( int n , char N ) ; // expected-note {{candidate function not viable: no known conversion from 'const char [6]' to 'char' for 2nd argument}}
2010-01-13 17:16:55 +08:00
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}}
2010-01-14 08:56:20 +08:00
2010-09-05 08:17:29 +08:00
void bar ( double d ) ; //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
void bar ( int i ) ; //expected-note {{candidate function not viable: 'this' argument has type 'const test1::A', but method is not marked const}}
2010-01-14 11:28:57 +08:00
2010-09-05 08:17:29 +08:00
void baz ( A & d ) ; // expected-note {{candidate function not viable: 1st argument ('const test1::A') would lose const qualifier}}
void baz ( int i ) ; // expected-note {{candidate function not viable: no known conversion from 'const test1::A' to 'int' for 1st argument}}
2012-05-11 13:16:41 +08:00
// PR 11857
2012-05-15 14:21:54 +08:00
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 rab ( double n , int u = 0 ) ; // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
void rab ( int n , int u = 0 ) ; // expected-note {{candidate function not viable: requires at least argument 'n', but no arguments were provided}}
2012-05-11 13:16:41 +08:00
void zab ( double n = 0.0 , int u = 0 ) ; // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
void zab ( int n = 0 , int u = 0 ) ; // expected-note {{candidate function not viable: requires at most 2 arguments, but 3 were provided}}
2010-01-13 17:16:55 +08:00
} ;
void test ( ) {
A a ;
a . foo ( 4 , " hello " ) ; //expected-error {{no matching member function for call to 'foo'}}
2010-01-14 08:56:20 +08:00
Rework base and member initialization in constructors, with several
(necessarily simultaneous) changes:
- CXXBaseOrMemberInitializer now contains only a single initializer
rather than a set of initialiation arguments + a constructor. The
single initializer covers all aspects of initialization, including
constructor calls as necessary but also cleanup of temporaries
created by the initializer (which we never handled
before!).
- Rework + simplify code generation for CXXBaseOrMemberInitializers,
since we can now just emit the initializer as an initializer.
- Switched base and member initialization over to the new
initialization code (InitializationSequence), so that it
- Improved diagnostics for the new initialization code when
initializing bases and members, to match the diagnostics produced
by the previous (special-purpose) code.
- Simplify the representation of type-checked constructor initializers in
templates; instead of keeping the fully-type-checked AST, which is
rather hard to undo at template instantiation time, throw away the
type-checked AST and store the raw expressions in the AST. This
simplifies instantiation, but loses a little but of information in
the AST.
- When type-checking implicit base or member initializers within a
dependent context, don't add the generated initializers into the
AST, because they'll look like they were explicit.
- Record in CXXConstructExpr when the constructor call is to
initialize a base class, so that CodeGen does not have to infer it
from context. This ensures that we call the right kind of
constructor.
There are also a few "opportunity" fixes here that were needed to not
regress, for example:
- Diagnose default-initialization of a const-qualified class that
does not have a user-declared default constructor. We had this
diagnostic specifically for bases and members, but missed it for
variables. That's fixed now.
- When defining the implicit constructors, destructor, and
copy-assignment operator, set the CurContext to that constructor
when we're defining the body.
llvm-svn: 94952
2010-01-31 17:12:51 +08:00
const A b = A ( ) ;
2010-01-14 08:56:20 +08:00
b . bar ( 0 ) ; //expected-error {{no matching member function for call to 'bar'}}
2010-01-14 11:28:57 +08:00
a . baz ( b ) ; //expected-error {{no matching member function for call to 'baz'}}
2012-05-11 13:16:41 +08:00
a . rab ( ) ; //expected-error {{no matching member function for call to 'rab'}}
a . zab ( 3 , 4 , 5 ) ; //expected-error {{no matching member function for call to 'zab'}}
2010-01-13 17:16:55 +08:00
}
}
2013-01-26 10:07:32 +08:00
namespace b7398190 {
struct S {
int f ( ) ; // expected-note {{'this' argument has type 'const b7398190::S', but method is not marked const}}
void f ( int ) ; // expected-note {{requires 1 argument, but 0 were provided}}
} ;
const S * p ;
int k = p - > f ( ) ; // expected-error {{no matching member function for call to 'f'}}
}