2014-01-15 03:35:09 +08:00
// RUN: %clang_cc1 -std=c++11 -triple %itanium_abi_triple -fsyntax-only -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -verify %s
// RUN: %clang_cc1 -std=c++11 -triple %ms_abi_triple -DMSABI -fsyntax-only -Wnon-virtual-dtor -Wdelete-non-virtual-dtor -verify %s
2008-11-06 04:51:48 +08:00
class A {
public :
~ A ( ) ;
} ;
class B {
public :
~ B ( ) { }
} ;
class C {
public :
( ~ C ) ( ) { }
} ;
struct D {
static void ~ D ( int , . . . ) const { } / / \
2012-02-10 19:05:11 +08:00
/ / expected - error { { static member function cannot have ' const ' qualifier } } \
2008-11-06 04:51:48 +08:00
/ / expected - error { { destructor cannot be declared ' static ' } } \
/ / expected - error { { destructor cannot have any parameters } } \
2010-07-01 13:10:53 +08:00
/ / expected - error { { destructor cannot be variadic } } \
/ / expected - error { { destructor cannot have a return type } } \
// expected-error{{'const' qualifier is not allowed on a destructor}}
2008-11-06 04:51:48 +08:00
} ;
2009-04-25 16:28:21 +08:00
struct D2 {
void ~ D2 ( ) { } / / \
// expected-error{{destructor cannot have a return type}}
} ;
2009-04-25 16:06:05 +08:00
2008-11-06 04:51:48 +08:00
struct E ;
typedef E E_typedef ;
struct E {
2010-03-10 19:27:22 +08:00
~ E_typedef ( ) ; // expected-error{{destructor cannot be declared using a typedef 'E_typedef' (aka 'E') of the class name}}
2008-11-06 04:51:48 +08:00
} ;
struct F {
2008-11-24 07:12:31 +08:00
( ~ F ) ( ) ; // expected-note {{previous declaration is here}}
~ F ( ) ; // expected-error {{destructor cannot be redeclared}}
2008-11-06 04:51:48 +08:00
} ;
2010-02-17 03:09:40 +08:00
~ ; // expected-error {{expected a class name after '~' to name a destructor}}
2009-07-21 06:41:12 +08:00
~ undef ( ) ; // expected-error {{expected the class name after '~' to name a destructor}}
2010-02-17 03:09:40 +08:00
~ operator + ( int , int ) ; // expected-error {{expected a class name after '~' to name a destructor}}
2008-11-08 06:02:30 +08:00
~ F ( ) { } // expected-error {{destructor must be a non-static member function}}
2008-12-12 16:25:50 +08:00
struct G {
~ G ( ) ;
} ;
G : : ~ G ( ) { }
2009-05-01 07:18:11 +08:00
// <rdar://problem/6841210>
struct H {
~ H ( void ) { }
} ;
2009-07-21 23:28:50 +08:00
struct X { } ;
struct Y {
~ X ( ) ; // expected-error {{expected the class name after '~' to name the enclosing class}}
} ;
2010-02-26 02:11:54 +08:00
namespace PR6421 {
class T ; // expected-note{{forward declaration}}
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
class QGenericArgument // expected-note{{declared here}}
2010-02-26 02:11:54 +08:00
{
template < typename U >
void foo ( T t ) / / expected - error { { variable has incomplete type } }
{ }
void disconnect ( )
{
T * t ;
When we run into an error parsing or type-checking the left-hand side
of a binary expression, continue on and parse the right-hand side of
the binary expression anyway, but don't call the semantic actions to
type-check. Previously, we would see the error and then, effectively,
skip tokens until the end of the statement.
The result should be more useful recovery, both in the normal case
(we'll actually see errors beyond the first one in a statement), but
it also helps code completion do a much better job, because we do
"real" code completion on the right-hand side of an invalid binary
expression rather than completing with the recovery completion. For
example, given
x = p->y
if there is no variable named "x", we can still complete after the p->
as a member expression. Along the recovery path, we would have
completed after the "->" as if we were in an expression context, which
is mostly useless.
llvm-svn: 114225
2010-09-18 06:25:06 +08:00
bob < QGenericArgument > ( t ) ; / / expected - error { { undeclared identifier ' bob ' } } \
// expected-error{{does not refer to a value}}
2010-02-26 02:11:54 +08:00
}
} ;
}
2010-03-26 14:57:13 +08:00
namespace PR6709 {
2014-01-14 03:48:13 +08:00
# ifdef MSABI
// This bug, "Clang instantiates destructor for function argument" is intended
// behaviour in the Microsoft ABI because the callee needs to destruct the arguments.
// expected-error@+3 {{indirection requires pointer operand ('int' invalid)}}
// expected-note@+3 {{in instantiation of member function 'PR6709::X<int>::~X' requested here}}
# endif
2010-03-26 14:57:13 +08:00
template < class T > class X { T v ; ~ X ( ) { + + * v ; } } ;
void a ( X < int > x ) { }
}
2010-07-01 13:10:53 +08:00
struct X0 { virtual ~ X0 ( ) throw ( ) ; } ;
struct X1 : public X0 { } ;
2010-07-04 02:33:00 +08:00
// Make sure we instantiate operator deletes when building a virtual
// destructor.
namespace test6 {
template < class T > class A {
public :
2010-07-04 04:33:13 +08:00
void * operator new ( __SIZE_TYPE__ ) ;
2010-07-04 02:33:00 +08:00
void operator delete ( void * p ) {
T : : deleteIt ( p ) ; // expected-error {{type 'int' cannot be used prior to '::'}}
}
2014-01-14 03:48:13 +08:00
# ifdef MSABI
// expected-note@+2 {{in instantiation of member function 'test6::A<int>::operator delete' requested here}}
# endif
2010-11-25 08:35:20 +08:00
virtual ~ A ( ) { }
2010-07-04 02:33:00 +08:00
} ;
2014-01-14 03:48:13 +08:00
# ifndef MSABI
// expected-note@+2 {{in instantiation of member function 'test6::A<int>::operator delete' requested here}}
# endif
class B : A < int > { B ( ) ; } ;
2010-11-25 08:35:20 +08:00
B : : B ( ) { }
2010-07-04 02:33:00 +08:00
}
2010-08-12 08:57:17 +08:00
// Make sure classes are marked invalid when they have invalid
// members. This avoids a crash-on-invalid.
namespace test7 {
struct A {
~ A ( ) const ; // expected-error {{'const' qualifier is not allowed on a destructor}}
} ;
struct B : A { } ;
void test ( ) {
B * b ;
b - > ~ B ( ) ;
}
}
2011-01-31 15:05:00 +08:00
namespace nonvirtualdtor {
struct S1 { // expected-warning {{has virtual functions but non-virtual destructor}}
virtual void m ( ) ;
} ;
struct S2 {
~ S2 ( ) ; // expected-warning {{has virtual functions but non-virtual destructor}}
virtual void m ( ) ;
} ;
struct S3 : public S1 { // expected-warning {{has virtual functions but non-virtual destructor}}
virtual void m ( ) ;
} ;
struct S4 : public S2 { // expected-warning {{has virtual functions but non-virtual destructor}}
virtual void m ( ) ;
} ;
struct B {
virtual ~ B ( ) ;
virtual void m ( ) ;
} ;
struct S5 : public B {
virtual void m ( ) ;
} ;
2011-02-01 01:10:25 +08:00
struct S6 {
virtual void m ( ) ;
private :
~ S6 ( ) ;
} ;
struct S7 {
virtual void m ( ) ;
protected :
~ S7 ( ) ;
} ;
2011-02-03 02:47:41 +08:00
template < class T > class TS : public B {
virtual void m ( ) ;
} ;
TS < int > baz ;
template < class T > class TS2 { // expected-warning {{'nonvirtualdtor::TS2<int>' has virtual functions but non-virtual destructor}}
virtual void m ( ) ;
} ;
TS2 < int > foo ; // expected-note {{instantiation}}
2011-01-31 15:05:00 +08:00
}
2011-02-20 03:14:36 +08:00
2011-05-25 03:53:26 +08:00
namespace dnvd { // delete-non-virtual-dtor warning
struct NP { } ;
struct B { // expected-warning {{has virtual functions but non-virtual destructor}}
virtual void foo ( ) ;
} ;
struct D : B { } ; // expected-warning {{has virtual functions but non-virtual destructor}}
struct F final : B { } ; // expected-warning {{has virtual functions but non-virtual destructor}}
struct VB {
virtual void foo ( ) ;
virtual ~ VB ( ) ;
} ;
struct VD : VB { } ;
struct VF final : VB { } ;
template < typename T >
class simple_ptr {
public :
simple_ptr ( T * t ) : _ptr ( t ) { }
~ simple_ptr ( ) { delete _ptr ; } / / \
/ / expected - warning { { delete called on ' dnvd : : B ' that has virtual functions but non - virtual destructor } } \
// expected-warning {{delete called on 'dnvd::D' that has virtual functions but non-virtual destructor}}
T & operator * ( ) const { return * _ptr ; }
private :
T * _ptr ;
} ;
template < typename T >
class simple_ptr2 {
public :
simple_ptr2 ( T * t ) : _ptr ( t ) { }
~ simple_ptr2 ( ) { delete _ptr ; } // expected-warning {{delete called on 'dnvd::B' that has virtual functions but non-virtual destructor}}
T & operator * ( ) const { return * _ptr ; }
private :
T * _ptr ;
} ;
void use ( B & ) ;
void use ( VB & ) ;
void nowarnstack ( ) {
B b ; use ( b ) ;
D d ; use ( d ) ;
F f ; use ( f ) ;
VB vb ; use ( vb ) ;
VD vd ; use ( vd ) ;
VF vf ; use ( vf ) ;
}
void nowarnnonpoly ( ) {
{
NP * np = new NP ( ) ;
delete np ;
}
{
NP * np = new NP [ 4 ] ;
delete [ ] np ;
}
}
void nowarnarray ( ) {
{
B * b = new B [ 4 ] ;
delete [ ] b ;
}
{
D * d = new D [ 4 ] ;
delete [ ] d ;
}
{
VB * vb = new VB [ 4 ] ;
delete [ ] vb ;
}
{
VD * vd = new VD [ 4 ] ;
delete [ ] vd ;
}
}
template < typename T >
void nowarntemplate ( ) {
{
T * t = new T ( ) ;
delete t ;
}
{
T * t = new T [ 4 ] ;
delete [ ] t ;
}
}
void nowarn0 ( ) {
{
F * f = new F ( ) ;
delete f ;
}
{
VB * vb = new VB ( ) ;
delete vb ;
}
{
VB * vb = new VD ( ) ;
delete vb ;
}
{
VD * vd = new VD ( ) ;
delete vd ;
}
{
VF * vf = new VF ( ) ;
delete vf ;
}
}
void warn0 ( ) {
{
B * b = new B ( ) ;
delete b ; // expected-warning {{delete called on 'dnvd::B' that has virtual functions but non-virtual destructor}}
}
{
B * b = new D ( ) ;
delete b ; // expected-warning {{delete called on 'dnvd::B' that has virtual functions but non-virtual destructor}}
}
{
D * d = new D ( ) ;
delete d ; // expected-warning {{delete called on 'dnvd::D' that has virtual functions but non-virtual destructor}}
}
}
void nowarn1 ( ) {
{
simple_ptr < F > f ( new F ( ) ) ;
use ( * f ) ;
}
{
simple_ptr < VB > vb ( new VB ( ) ) ;
use ( * vb ) ;
}
{
simple_ptr < VB > vb ( new VD ( ) ) ;
use ( * vb ) ;
}
{
simple_ptr < VD > vd ( new VD ( ) ) ;
use ( * vd ) ;
}
{
simple_ptr < VF > vf ( new VF ( ) ) ;
use ( * vf ) ;
}
}
void warn1 ( ) {
{
simple_ptr < B > b ( new B ( ) ) ; // expected-note {{in instantiation of member function 'dnvd::simple_ptr<dnvd::B>::~simple_ptr' requested here}}
use ( * b ) ;
}
{
simple_ptr2 < B > b ( new D ( ) ) ; // expected-note {{in instantiation of member function 'dnvd::simple_ptr2<dnvd::B>::~simple_ptr2' requested here}}
use ( * b ) ;
}
{
simple_ptr < D > d ( new D ( ) ) ; // expected-note {{in instantiation of member function 'dnvd::simple_ptr<dnvd::D>::~simple_ptr' requested here}}
use ( * d ) ;
}
}
}
2011-02-20 03:14:36 +08:00
namespace PR9238 {
class B { public : ~ B ( ) ; } ;
class C : virtual B { public : ~ C ( ) { } } ;
}
2011-03-05 06:32:08 +08:00
namespace PR7900 {
struct A { // expected-note 2{{type 'PR7900::A' is declared here}}
} ;
struct B : public A {
} ;
void foo ( ) {
B b ;
b . ~ B ( ) ;
b . ~ A ( ) ; // expected-error{{destructor type 'PR7900::A' in object destruction expression does not match the type 'PR7900::B' of the object being destroyed}}
( & b ) - > ~ A ( ) ; // expected-error{{destructor type 'PR7900::A' in object destruction expression does not match the type 'PR7900::B' of the object being destroyed}}
}
}
2013-10-10 17:44:41 +08:00
namespace PR16892 {
auto p = & A : : ~ A ; // expected-error{{taking the address of a destructor}}
}