[cfe-commits] r128188 - in /cfe/trunk: include/clang/Basic/DiagnosticGroups.td include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/SemaDeclCXX.cpp test/SemaCXX/warn-exit-time-destructors.cpp

Anders Carlsson andersca at mac.com
Wed Mar 23 18:01:42 PDT 2011


Author: andersca
Date: Wed Mar 23 20:01:41 2011
New Revision: 128188

URL: http://llvm.org/viewvc/llvm-project?rev=128188&view=rev
Log:
Add a new warning for exit-time destructors.

Added:
    cfe/trunk/test/SemaCXX/warn-exit-time-destructors.cpp
Modified:
    cfe/trunk/include/clang/Basic/DiagnosticGroups.td
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/SemaDeclCXX.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticGroups.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticGroups.td?rev=128188&r1=128187&r2=128188&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticGroups.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticGroups.td Wed Mar 23 20:01:41 2011
@@ -55,6 +55,7 @@
 
 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">;

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=128188&r1=128187&r2=128188&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Wed Mar 23 20:01:41 2011
@@ -204,6 +204,9 @@
 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">;

Modified: cfe/trunk/lib/Sema/SemaDeclCXX.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaDeclCXX.cpp?rev=128188&r1=128187&r2=128188&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaDeclCXX.cpp (original)
+++ cfe/trunk/lib/Sema/SemaDeclCXX.cpp Wed Mar 23 20:01:41 2011
@@ -6102,9 +6102,13 @@
                             << 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);
+    }
   }
 }
 

Added: cfe/trunk/test/SemaCXX/warn-exit-time-destructors.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/warn-exit-time-destructors.cpp?rev=128188&view=auto
==============================================================================
--- cfe/trunk/test/SemaCXX/warn-exit-time-destructors.cpp (added)
+++ cfe/trunk/test/SemaCXX/warn-exit-time-destructors.cpp Wed Mar 23 20:01:41 2011
@@ -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];
+}
+
+}





More information about the cfe-commits mailing list