static local variables with destructors don't require a global destructor

unless we're on a platform without __cxa_atexit (or use thereof has been
disabled).  This patch actually just disables the check completely for
static locals, but I've filed http://llvm.org/bugs/show_bug.cgi?id=8176 to
track the platform-specific fix.

llvm-svn: 114269
This commit is contained in:
John McCall 2010-09-18 05:25:11 +00:00
parent b92b13d8a0
commit 386dfc738e
2 changed files with 11 additions and 4 deletions

View File

@ -5519,7 +5519,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
<< VD->getDeclName() << VD->getDeclName()
<< VD->getType()); << VD->getType());
if (!VD->isInvalidDecl() && VD->hasGlobalStorage()) // TODO: this should be re-enabled for static locals by !CXAAtExit
if (!VD->isInvalidDecl() && VD->hasGlobalStorage() && !VD->isStaticLocal())
Diag(VD->getLocation(), diag::warn_global_destructor); Diag(VD->getLocation(), diag::warn_global_destructor);
} }
} }

View File

@ -72,7 +72,7 @@ namespace test6 {
struct A { ~A(); }; struct A { ~A(); };
void f1() { void f1() {
static A a; // expected-warning {{global destructor}} static A a;
} }
void f2() { void f2() {
static A& a = *new A; static A& a = *new A;
@ -84,8 +84,14 @@ namespace pr8095 {
int x; int x;
Foo(int x1) : x(x1) {} Foo(int x1) : x(x1) {}
}; };
void foo() {
void bar() {
static Foo a(0); static Foo a(0);
} }
struct Bar {
~Bar();
};
void bar() {
static Bar b;
}
} }