2014-11-06 18:10:50 +08:00
// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions %s
// RUN: %clang_cc1 -fsyntax-only -verify -fexceptions -fcxx-exceptions -std=c++11 %s
2009-09-26 02:43:00 +08:00
template void * ; // expected-error{{expected unqualified-id}}
template typedef void f0 ; // expected-error{{explicit instantiation of typedef}}
int v0 ; // expected-note{{refers here}}
template int v0 ; // expected-error{{does not refer}}
template < typename T >
struct X0 {
static T value ;
T f0 ( T x ) {
return x + 1 ; // expected-error{{invalid operands}}
2014-11-06 18:10:50 +08:00
}
T * f0 ( T * , T * ) { return T ( ) ; } // expected-warning 0-1 {{expression which evaluates to zero treated as a null pointer constant of type 'int *'}} expected-error 0-1 {{cannot initialize return object of type 'int *' with an rvalue of type 'int'}}
2013-07-20 07:00:19 +08:00
2013-12-14 09:07:05 +08:00
template < typename U > T f0 ( T , U ) { return T ( ) ; } / / expected - note - re { { candidate template ignored : could not match ' int ( int , U ) { { ( __attribute__ \ ( \ ( thiscall \ ) \ ) ) ? } } ' against ' int ( int ) { { ( __attribute__ \ ( \ ( thiscall \ ) \ ) ) ? } } const ' } } \
2013-07-20 07:00:19 +08:00
// expected-note {{candidate template ignored: could not match 'int' against 'int *'}}
2009-09-26 02:43:00 +08:00
} ;
2009-10-15 07:41:34 +08:00
template < typename T >
T X0 < T > : : value ; // expected-error{{no matching constructor}}
2009-09-26 02:43:00 +08:00
template int X0 < int > : : value ;
2014-11-06 18:10:50 +08:00
struct NotDefaultConstructible { // expected-note{{candidate constructor (the implicit copy constructor)}} expected-note 0-1 {{candidate constructor (the implicit move constructor)}}
2010-01-06 17:43:14 +08:00
NotDefaultConstructible ( int ) ; // expected-note{{candidate constructor}}
2009-09-26 02:43:00 +08:00
} ;
2009-10-15 07:41:34 +08:00
template NotDefaultConstructible X0 < NotDefaultConstructible > : : value ; // expected-note{{instantiation}}
2009-09-26 02:43:00 +08:00
template int X0 < int > : : f0 ( int ) ;
2012-08-09 01:33:31 +08:00
template int * X0 < int > : : f0 ( int * , int * ) ; // expected-note{{in instantiation of member function 'X0<int>::f0' requested here}}
2009-09-26 02:43:00 +08:00
template int X0 < int > : : f0 ( int , float ) ;
template int X0 < int > : : f0 ( int ) const ; // expected-error{{does not refer}}
template int * X0 < int > : : f0 ( int * , float * ) ; // expected-error{{does not refer}}
struct X1 { } ;
typedef int X1 : : * MemPtr ;
template MemPtr X0 < MemPtr > : : f0 ( MemPtr ) ; // expected-note{{requested here}}
struct X2 {
int f0 ( int ) ; // expected-note{{refers here}}
2009-10-15 07:41:34 +08:00
template < typename T > T f1 ( T ) { return T ( ) ; }
template < typename T > T * f1 ( T * ) { return 0 ; }
2009-09-26 02:43:00 +08:00
2009-10-15 07:41:34 +08:00
template < typename T , typename U > void f2 ( T , U * ) { } // expected-note{{candidate}}
template < typename T , typename U > void f2 ( T * , U ) { } // expected-note{{candidate}}
2009-09-26 02:43:00 +08:00
} ;
template int X2 : : f0 ( int ) ; // expected-error{{not an instantiation}}
template int * X2 : : f1 ( int * ) ; // okay
template void X2 : : f2 ( int * , int * ) ; // expected-error{{ambiguous}}
2009-09-26 05:45:23 +08:00
2013-07-20 07:00:19 +08:00
template < typename T >
void print_type ( ) { } // expected-note {{candidate template ignored: could not match 'void ()' against 'void (float *)'}}
2009-09-26 05:45:23 +08:00
template void print_type < int > ( ) ;
template void print_type < float > ( ) ;
2013-07-20 07:00:19 +08:00
template < typename T >
void print_type ( T * ) { } // expected-note {{candidate template ignored: could not match 'void (int *)' against 'void (float *)'}}
2009-09-26 05:45:23 +08:00
template void print_type ( int * ) ;
template void print_type < int > ( float * ) ; // expected-error{{does not refer}}
void print_type ( double * ) ;
template void print_type < double > ( double * ) ;
2009-10-02 07:51:25 +08:00
// PR5069
template < int I > void foo0 ( int ( & ) [ I + 1 ] ) { }
template void foo0 < 2 > ( int ( & ) [ 3 ] ) ;
2010-02-13 18:17:50 +08:00
namespace explicit_instantiation_after_implicit_instantiation {
template < int I > struct X0 { static int x ; } ;
template < int I > int X0 < I > : : x ;
void test1 ( ) { ( void ) & X0 < 1 > : : x ; }
template struct X0 < 1 > ;
}
2010-07-13 08:10:04 +08:00
2010-12-02 04:32:20 +08:00
template < typename > struct X3 { } ;
inline template struct X3 < int > ; // expected-warning{{ignoring 'inline' keyword on explicit template instantiation}}
static template struct X3 < float > ; // expected-warning{{ignoring 'static' keyword on explicit template instantiation}}
2011-04-25 00:27:48 +08:00
namespace PR7622 {
2010-07-13 08:10:04 +08:00
template < typename , typename = int >
struct basic_streambuf ;
template < typename , typename >
2017-05-11 05:32:16 +08:00
struct basic_streambuf { friend bob < > ( ) } ; / / expected - error { { no template named ' bob ' } } \
2013-07-20 07:00:19 +08:00
// expected-error{{expected member name or ';' after declaration specifiers}}
2011-04-25 00:27:48 +08:00
template struct basic_streambuf < int > ;
}
2011-12-23 10:16:45 +08:00
// Test that we do not crash.
class TC1 {
class TC2 {
2017-02-10 06:14:25 +08:00
template
void foo ( ) { } // expected-error{{expected '<' after 'template'}}
2011-12-23 10:16:45 +08:00
} ;
} ;
2013-09-12 01:04:24 +08:00
namespace PR8020 {
template < typename T > struct X { X ( ) { } } ;
template < > struct X < int > { X ( ) ; } ;
template X < int > : : X ( ) { } // expected-error{{function cannot be defined in an explicit instantiation}}
}
namespace PR10086 {
template void foobar ( int i ) { } // expected-error{{function cannot be defined in an explicit instantiation}}
int func ( ) {
foobar ( 5 ) ;
}
}
2013-09-28 04:14:12 +08:00
namespace undefined_static_data_member {
template < typename T > struct A {
static int a ; // expected-note {{here}}
2017-12-09 20:09:54 +08:00
template < typename U > static int b ; // expected-note {{here}} expected-warning 0+ {{extension}}
2013-09-28 04:14:12 +08:00
} ;
struct B {
2017-12-09 20:09:54 +08:00
template < typename U > static int c ; // expected-note {{here}} expected-warning 0+ {{extension}}
2013-09-28 04:14:12 +08:00
} ;
template int A < int > : : a ; // expected-error {{explicit instantiation of undefined static data member 'a' of class template 'undefined_static_data_member::A<int>'}}
template int A < int > : : b < int > ; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::A<int>::b<int>'}}
template int B : : c < int > ; // expected-error {{explicit instantiation of undefined variable template 'undefined_static_data_member::B::c<int>'}}
template < typename T > struct C {
static int a ;
2017-12-09 20:09:54 +08:00
template < typename U > static int b ; // expected-warning 0+ {{extension}}
2013-09-28 04:14:12 +08:00
} ;
struct D {
2017-12-09 20:09:54 +08:00
template < typename U > static int c ; // expected-warning 0+ {{extension}}
2013-09-28 04:14:12 +08:00
} ;
template < typename T > int C < T > : : a ;
2017-12-09 20:09:54 +08:00
template < typename T > template < typename U > int C < T > : : b ; // expected-warning 0+ {{extension}}
template < typename U > int D : : c ; // expected-warning 0+ {{extension}}
2013-09-28 04:14:12 +08:00
template int C < int > : : a ;
template int C < int > : : b < int > ;
template int D : : c < int > ;
}
2014-11-06 18:10:50 +08:00
// expected-note@+1 3-4 {{explicit instantiation refers here}}
template < class T > void Foo ( T i ) throw ( T ) { throw i ; }
// expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}}
template void Foo ( int a ) throw ( char ) ;
// expected-error@+1 {{exception specification in explicit instantiation does not match instantiated one}}
template void Foo ( double a ) throw ( ) ;
// expected-error@+1 1 {{exception specification in explicit instantiation does not match instantiated one}}
template void Foo ( long a ) throw ( long , char ) ;
template void Foo ( float a ) ;
# if __cplusplus >= 201103L
// expected-error@+1 0-1 {{exception specification in explicit instantiation does not match instantiated one}}
template void Foo ( double a ) noexcept ;
# endif
Don't drop attributes when checking explicit specializations.
Consider a template class with attributes on a method, and an explicit
specialization of that method:
template <int>
struct A {
void foo() final;
};
template <>
void A<0>::foo() {}
In this example, the attribute is `final`, but it might also be an
__attribute__((visibility("foo"))), noreturn, inline, etc. clang's current
behavior is to strip all attributes, which for some attributes is wrong
(the snippet above allows a subclass of A<0> to override the final method, for
example) and for others disagrees with gcc.
So stop dropping attributes. r95845 added this code without a test case, and
r176728 added the code for dropping attributes on parameters (with tests, but
they still pass).
As an additional wrinkle, do drop dllimport and dllexport, since that's how
these two attributes work. (This is covered by existing tests.)
Fixes PR21942.
The approach is by Richard Smith, initial analysis and typing was done by me.
With this, clang also matches GCC and EDG on all attributes Richard tested.
llvm-svn: 224651
2014-12-20 07:52:45 +08:00
# if __cplusplus >= 201103L
namespace PR21942 {
template < int >
struct A {
virtual void foo ( ) final ;
} ;
template < >
void A < 0 > : : foo ( ) { } // expected-note{{overridden virtual function is here}}
struct B : A < 0 > {
virtual void foo ( ) override ; // expected-error{{declaration of 'foo' overrides a 'final' function}}
} ;
}
# endif