From 386dfc738e83df6c4b95e17a32a5dc84ef564756 Mon Sep 17 00:00:00 2001 From: John McCall Date: Sat, 18 Sep 2010 05:25:11 +0000 Subject: [PATCH] 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 --- clang/lib/Sema/SemaDeclCXX.cpp | 3 ++- clang/test/SemaCXX/warn-global-constructors.cpp | 12 +++++++++--- 2 files changed, 11 insertions(+), 4 deletions(-) diff --git a/clang/lib/Sema/SemaDeclCXX.cpp b/clang/lib/Sema/SemaDeclCXX.cpp index 0580392689b6..4816d22013fa 100644 --- a/clang/lib/Sema/SemaDeclCXX.cpp +++ b/clang/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/clang/test/SemaCXX/warn-global-constructors.cpp b/clang/test/SemaCXX/warn-global-constructors.cpp index 0391f5ba3d1f..ad609545ece1 100644 --- a/clang/test/SemaCXX/warn-global-constructors.cpp +++ b/clang/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 bar() { + void foo() { static Foo a(0); } + + struct Bar { + ~Bar(); + }; + void bar() { + static Bar b; + } }