]> granicus.if.org Git - clang/commitdiff
Properly implement C++0x [stmt.dcl]p3, which requires a scope to be
authorDouglas Gregor <dgregor@apple.com>
Wed, 15 Jun 2011 03:23:34 +0000 (03:23 +0000)
committerDouglas Gregor <dgregor@apple.com>
Wed, 15 Jun 2011 03:23:34 +0000 (03:23 +0000)
protected in the case where a variable is being initialized by a
trivial default constructor but has a non-trivial destructor.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133037 91177308-0d34-0410-b5e6-96231b3b80d8

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

index ec23778494225dffb761266ae085930844c2f281..ea736c0cd2e32c585e5bd10b5b05be94f9e85e8b 100644 (file)
@@ -2421,6 +2421,8 @@ def err_indirect_goto_in_protected_scope : Error<
 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<
index ae154aae20628013c5767e1fc3ed083753f78f4c..679f4fefa22dbadb9e4a5d80486b015113da70f4 100644 (file)
@@ -157,6 +157,9 @@ static std::pair<unsigned,unsigned>
                        : Record->isPOD()) &&
                     Constructor->isDefaultConstructor())
                   CallsTrivialConstructor = true;
+            
+            if (CallsTrivialConstructor && !Record->hasTrivialDestructor())
+              InDiag = diag::note_protected_by_variable_nontriv_destructor;
           }
           
           if (!CallsTrivialConstructor)
index b41504488e8e505961b7436d3323e1c0c4d9584f..40b4c23841c8220ffc1beebb3ba27fe4b21e632d 100644 (file)
@@ -30,13 +30,13 @@ struct Y {
 
 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();    
   }