aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnders Carlsson <andersca@mac.com>2011-03-24 01:01:41 +0000
committerAnders Carlsson <andersca@mac.com>2011-03-24 01:01:41 +0000
commit2b32dad701ef3e666e3b9cea02e1d094a1078c6f (patch)
treec9e7dc73e253f2bc5ede3663665807202bd0866c
parent5188507b9a1b09ec95c14ffadf0e832f2b47aa8a (diff)
Add a new warning for exit-time destructors.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128188 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Basic/DiagnosticGroups.td1
-rw-r--r--include/clang/Basic/DiagnosticSemaKinds.td3
-rw-r--r--lib/Sema/SemaDeclCXX.cpp10
-rw-r--r--test/SemaCXX/warn-exit-time-destructors.cpp27
4 files changed, 38 insertions, 3 deletions
diff --git a/include/clang/Basic/DiagnosticGroups.td b/include/clang/Basic/DiagnosticGroups.td
index 2b7c5de25c..3d2cbc486e 100644
--- a/include/clang/Basic/DiagnosticGroups.td
+++ b/include/clang/Basic/DiagnosticGroups.td
@@ -55,6 +55,7 @@ def CXXHexFloats : DiagGroup<"c++-hex-floats">;
def : DiagGroup<"c++0x-compat", [CXXHexFloats]>;
def : DiagGroup<"effc++">;
+def ExitTimeDestructors : DiagGroup<"exit-time-destructors">;
def FourByteMultiChar : DiagGroup<"four-char-constants">;
def GlobalConstructors : DiagGroup<"global-constructors">;
def : DiagGroup<"idiomatic-parentheses">;
diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td
index fa66d51369..dd82a46ba2 100644
--- a/include/clang/Basic/DiagnosticSemaKinds.td
+++ b/include/clang/Basic/DiagnosticSemaKinds.td
@@ -204,6 +204,9 @@ def warn_global_constructor : Warning<
def warn_global_destructor : Warning<
"declaration requires a global destructor">,
InGroup<GlobalConstructors>, DefaultIgnore;
+def warn_exit_time_destructor : Warning<
+ "declaration requires an exit-time destructor">,
+ InGroup<ExitTimeDestructors>, DefaultIgnore;
def err_invalid_thread : Error<
"'__thread' is only allowed on variable declarations">;
diff --git a/lib/Sema/SemaDeclCXX.cpp b/lib/Sema/SemaDeclCXX.cpp
index 220c22ad0f..edee86476b 100644
--- a/lib/Sema/SemaDeclCXX.cpp
+++ b/lib/Sema/SemaDeclCXX.cpp
@@ -6102,9 +6102,13 @@ void Sema::FinalizeVarWithDestructor(VarDecl *VD, const RecordType *Record) {
<< VD->getDeclName()
<< VD->getType());
- // 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);
+ if (!VD->isInvalidDecl() && VD->hasGlobalStorage()) {
+ // TODO: this should be re-enabled for static locals by !CXAAtExit
+ if (!VD->isStaticLocal())
+ Diag(VD->getLocation(), diag::warn_global_destructor);
+
+ Diag(VD->getLocation(), diag::warn_exit_time_destructor);
+ }
}
}
diff --git a/test/SemaCXX/warn-exit-time-destructors.cpp b/test/SemaCXX/warn-exit-time-destructors.cpp
new file mode 100644
index 0000000000..f49134b71c
--- /dev/null
+++ b/test/SemaCXX/warn-exit-time-destructors.cpp
@@ -0,0 +1,27 @@
+// RUN: %clang_cc1 -fsyntax-only -Wexit-time-destructors %s -verify
+
+namespace test1 {
+ struct A { ~A(); };
+ A a; // expected-warning {{declaration requires an exit-time destructor}}
+ A b[10]; // expected-warning {{declaration requires an exit-time destructor}}
+ A c[10][10]; // expected-warning {{declaration requires an exit-time destructor}}
+
+ A &d = a;
+ A &e = b[5];
+ A &f = c[5][7];
+}
+
+namespace test2 {
+void f() {
+ struct A { ~A() { } };
+
+ static A a; // expected-warning {{declaration requires an exit-time destructor}}
+ static A b[10]; // expected-warning {{declaration requires an exit-time destructor}}
+ static A c[10][10]; // expected-warning {{declaration requires an exit-time destructor}}
+
+ static A &d = a;
+ static A &e = b[5];
+ static A &f = c[5][7];
+}
+
+}