aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn McCall <rjmccall@apple.com>2010-09-18 05:25:11 +0000
committerJohn McCall <rjmccall@apple.com>2010-09-18 05:25:11 +0000
commitae79222014a7a90a2c2d4a04e67deac0012a0461 (patch)
tree582630fe77479738bfd35aff12a2abcb2f7ddcc5
parent8abdbd8118e37e759d1ce3f5814ee0a24b1589e8 (diff)
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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@114269 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--lib/Sema/SemaDeclCXX.cpp3
-rw-r--r--test/SemaCXX/warn-global-constructors.cpp10
2 files changed, 10 insertions, 3 deletions
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 0580392689..4816d22013 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -5519,7 +5519,8 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
<< VD->getDeclName()
<< 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);
}
}
diff --git a/test/SemaCXX/warn-global-constructors.cpp b/test/SemaCXX/warn-global-constructors.cpp
index 0391f5ba3d..ad609545ec 100644
--- a/test/SemaCXX/warn-global-constructors.cpp
+++ b/test/SemaCXX/warn-global-constructors.cpp
@@ -72,7 +72,7 @@ namespace test6 {
struct A { ~A(); };
void f1() {
- static A a; // expected-warning {{global destructor}}
+ static A a;
}
void f2() {
static A& a = *new A;
@@ -84,8 +84,14 @@ namespace pr8095 {
int x;
Foo(int x1) : x(x1) {}
};
+ void foo() {
+ static Foo a(0);
+ }
+ struct Bar {
+ ~Bar();
+ };
void bar() {
- static Foo a(0);
+ static Bar b;
}
}