]> granicus.if.org Git - clang/commitdiff
Add a new warning for exit-time destructors.
authorAnders Carlsson <andersca@mac.com>
Thu, 24 Mar 2011 01:01:41 +0000 (01:01 +0000)
committerAnders Carlsson <andersca@mac.com>
Thu, 24 Mar 2011 01:01:41 +0000 (01:01 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128188 91177308-0d34-0410-b5e6-96231b3b80d8

include/clang/Basic/DiagnosticGroups.td
include/clang/Basic/DiagnosticSemaKinds.td
lib/Sema/SemaDeclCXX.cpp
test/SemaCXX/warn-exit-time-destructors.cpp [new file with mode: 0644]

index 2b7c5de25c9b3dcc13c381a116ed1ada69536b47..3d2cbc486e40e22c46f8fde82df418fd3a550fce 100644 (file)
@@ -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">;
index fa66d51369f9700ebbda67d2f8024387c45e7390..dd82a46ba277db453f1e854da09480ce5c0e0765 100644 (file)
@@ -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">;
index 220c22ad0f54294741c9e54ed7ee15b6edd8f299..edee86476bab954b2e2bb9e59e72bb226f3e3f6f 100644 (file)
@@ -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 (file)
index 0000000..f49134b
--- /dev/null
@@ -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];
+}
+
+}