2011-10-14 06:29:44 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -std=c++11 %s
2011-03-17 03:16:25 +08:00
namespace std {
class type_info { } ;
}
2011-03-12 09:48:56 +08:00
void one ( ) { }
2011-10-12 07:14:30 +08:00
void two ( ) { } // expected-note 4{{possible target for call}}
void two ( int ) { } // expected-note 4{{possible target for call}}
2011-03-12 09:48:56 +08:00
2011-10-12 07:14:30 +08:00
template < class T > void twoT ( ) { } // expected-note 5{{possible target for call}}
template < class T > void twoT ( int ) { } // expected-note 5{{possible target for call}}
2011-03-12 09:48:56 +08:00
template < class T > void oneT ( ) { }
template < class T , class U > void oneT ( U ) { }
/*
The target can be
an object or reference being initialized ( 8.5 , 8.5 .3 ) ,
the left side of an assignment ( 5.17 ) ,
a parameter of a function ( 5.2 .2 ) ,
a parameter of a user - defined operator ( 13.5 ) ,
the return value of a function , operator function , or conversion ( 6.6 .3 ) ,
an explicit type conversion ( 5.2 .3 , 5.2 .9 , 5.4 ) , or
a non - type template - parameter ( 14.3 .2 )
*/
//#include <typeinfo>
template < void ( * p ) ( int ) > struct test { } ;
int main ( )
{
one ; // expected-warning {{expression result unused}}
2011-10-12 07:14:30 +08:00
two ; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}}
2011-03-12 09:48:56 +08:00
oneT < int > ; // expected-warning {{expression result unused}}
2011-10-12 07:14:30 +08:00
twoT < int > ; // expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
2011-03-17 03:16:25 +08:00
typeid ( oneT < int > ) ; // expected-warning{{expression result unused}}
2013-08-14 06:26:42 +08:00
sizeof ( oneT < int > ) ; // expected-error {{invalid application of 'sizeof' to a function type}}
2011-10-12 07:14:30 +08:00
sizeof ( twoT < int > ) ; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
2011-03-12 09:48:56 +08:00
decltype ( oneT < int > ) * fun = 0 ;
* one ; // expected-warning {{expression result unused}}
* oneT < int > ; // expected-warning {{expression result unused}}
2011-10-12 07:14:30 +08:00
* two ; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{indirection requires pointer operand}}
* twoT < int > ; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}}
2011-12-10 05:42:37 +08:00
! oneT < int > ; // expected-warning {{expression result unused}} expected-warning {{address of function 'oneT<int>' will always evaluate to 'true'}} expected-note {{prefix with the address-of operator to silence this warning}}
2011-03-12 09:48:56 +08:00
+ oneT < int > ; // expected-warning {{expression result unused}}
- oneT < int > ; //expected-error {{invalid argument type}}
2011-08-17 17:34:37 +08:00
oneT < int > = = 0 ; / / expected - warning { { equality comparison result unused } } \
2014-02-26 10:36:06 +08:00
/ / expected - note { { use ' = ' to turn this equality comparison into an assignment } } \
/ / expected - warning { { comparison of function ' oneT < int > ' equal to a null pointer is always false } } \
// expected-note {{prefix with the address-of operator to silence this warning}}
0 = = oneT < int > ; / / expected - warning { { equality comparison result unused } } \
/ / expected - warning { { comparison of function ' oneT < int > ' equal to a null pointer is always false } } \
// expected-note {{prefix with the address-of operator to silence this warning}}
0 ! = oneT < int > ; / / expected - warning { { inequality comparison result unused } } \
/ / expected - warning { { comparison of function ' oneT < int > ' not equal to a null pointer is always true } } \
// expected-note {{prefix with the address-of operator to silence this warning}}
2011-03-12 09:48:56 +08:00
( false ? one : oneT < int > ) ; // expected-warning {{expression result unused}}
void ( * p1 ) ( int ) ; p1 = oneT < int > ;
int i = ( int ) ( false ? ( void ( * ) ( int ) ) twoT < int > : oneT < int > ) ; //expected-error {{incompatible operand}}
2011-10-12 07:14:30 +08:00
( twoT < int > ) = = oneT < int > ; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
2011-12-10 05:42:37 +08:00
bool b = oneT < int > ; // expected-warning {{address of function 'oneT<int>' will always evaluate to 'true'}} expected-note {{prefix with the address-of operator to silence this warning}}
2011-03-12 09:48:56 +08:00
void ( * p ) ( ) = oneT < int > ;
2011-03-17 03:16:25 +08:00
test < oneT < int > > ti ;
2011-03-12 09:48:56 +08:00
void ( * u ) ( int ) = oneT < int > ;
b = ( void ( * ) ( ) ) twoT < int > ;
one < one ; / / expected - warning { { self - comparison always evaluates to false } } \
2014-03-11 11:11:08 +08:00
//expected-warning {{relational comparison result unused}}
2011-03-12 09:48:56 +08:00
oneT < int > < oneT < int > ; / / expected - warning { { self - comparison always evaluates to false } } \
2014-03-11 11:11:08 +08:00
//expected-warning {{relational comparison result unused}}
2011-03-12 09:48:56 +08:00
2011-10-12 07:14:30 +08:00
two < two ; //expected-error 2 {{reference to overloaded function could not be resolved; did you mean to call it with no arguments?}} expected-error {{invalid operands to binary expression ('void' and 'void')}}
twoT < int > < twoT < int > ; //expected-error {{reference to overloaded function could not be resolved; did you mean to call it?}} {{cannot resolve overloaded function 'twoT' from context}}
2011-08-17 17:34:37 +08:00
oneT < int > = = 0 ; / / expected - warning { { equality comparison result unused } } \
2014-02-26 10:36:06 +08:00
/ / expected - note { { use ' = ' to turn this equality comparison into an assignment } } \
/ / expected - warning { { comparison of function ' oneT < int > ' equal to a null pointer is always false } } \
// expected-note {{prefix with the address-of operator to silence this warning}}
2011-03-12 09:48:56 +08:00
}
2011-03-17 03:16:25 +08:00
struct rdar9108698 {
2013-06-04 08:28:46 +08:00
template < typename > void f ( ) ; // expected-note{{possible target for call}}
2011-03-17 03:16:25 +08:00
} ;
void test_rdar9108698 ( rdar9108698 x ) {
2011-10-12 07:14:30 +08:00
x . f < int > ; // expected-error{{reference to non-static member function must be called}}
2011-03-17 03:16:25 +08:00
}
2019-06-21 03:49:13 +08:00
namespace GCC_PR67898 {
void f ( int ) ;
void f ( float ) ;
template < typename T , T F , T G , bool b = F = = G > struct X {
static_assert ( b , " " ) ;
} ;
template < typename T > void test1 ( ) { X < void ( T ) , f , f > ( ) ; }
template < typename T > void test2 ( ) { X < void ( * ) ( T ) , f , f > ( ) ; }
template void test1 < int > ( ) ;
template void test2 < int > ( ) ;
}