[cfe-commits] r133037 - in /cfe/trunk: include/clang/Basic/DiagnosticSemaKinds.td lib/Sema/JumpDiagnostics.cpp test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp

Douglas Gregor dgregor at apple.com
Tue Jun 14 20:23:34 PDT 2011


Author: dgregor
Date: Tue Jun 14 22:23:34 2011
New Revision: 133037

URL: http://llvm.org/viewvc/llvm-project?rev=133037&view=rev
Log:
Properly implement C++0x [stmt.dcl]p3, which requires a scope to be
protected in the case where a variable is being initialized by a
trivial default constructor but has a non-trivial destructor.

Modified:
    cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
    cfe/trunk/lib/Sema/JumpDiagnostics.cpp
    cfe/trunk/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp

Modified: cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td?rev=133037&r1=133036&r2=133037&view=diff
==============================================================================
--- cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td (original)
+++ cfe/trunk/include/clang/Basic/DiagnosticSemaKinds.td Tue Jun 14 22:23:34 2011
@@ -2421,6 +2421,8 @@
 def note_indirect_goto_target : Note<"possible target of indirect goto">;
 def note_protected_by_variable_init : Note<
   "jump bypasses variable initialization">;
+def note_protected_by_variable_nontriv_destructor : Note<
+  "jump bypasses variable with a non-trivial destructor">;
 def note_protected_by_cleanup : Note<
   "jump bypasses initialization of variable with __attribute__((cleanup))">;
 def note_protected_by_vla_typedef : Note<

Modified: cfe/trunk/lib/Sema/JumpDiagnostics.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/JumpDiagnostics.cpp?rev=133037&r1=133036&r2=133037&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/JumpDiagnostics.cpp (original)
+++ cfe/trunk/lib/Sema/JumpDiagnostics.cpp Tue Jun 14 22:23:34 2011
@@ -157,6 +157,9 @@
                        : Record->isPOD()) &&
                     Constructor->isDefaultConstructor())
                   CallsTrivialConstructor = true;
+            
+            if (CallsTrivialConstructor && !Record->hasTrivialDestructor())
+              InDiag = diag::note_protected_by_variable_nontriv_destructor;
           }
           
           if (!CallsTrivialConstructor)

Modified: cfe/trunk/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp?rev=133037&r1=133036&r2=133037&view=diff
==============================================================================
--- cfe/trunk/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp (original)
+++ cfe/trunk/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp Tue Jun 14 22:23:34 2011
@@ -30,13 +30,13 @@
 
 void f();
 void test_Y() {
-  goto end;
-  Y y;
+  goto end; // expected-error{{goto into protected scope}}
+  Y y; // expected-note{{jump bypasses variable with a non-trivial destructor}}
  end:
   f();
-  goto inner;
+  goto inner; // expected-error{{goto into protected scope}}
   {
-    Y y2;
+    Y y2; // expected-note{{jump bypasses variable with a non-trivial destructor}}
   inner:
     f();    
   }





More information about the cfe-commits mailing list