From: Douglas Gregor Date: Wed, 15 Jun 2011 03:23:34 +0000 (+0000) Subject: Properly implement C++0x [stmt.dcl]p3, which requires a scope to be X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=1454cb952b76a7dc441f2ae1b7f8d998a54a23cf;p=clang 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. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@133037 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Basic/DiagnosticSemaKinds.td b/include/clang/Basic/DiagnosticSemaKinds.td index ec23778494..ea736c0cd2 100644 --- a/include/clang/Basic/DiagnosticSemaKinds.td +++ b/include/clang/Basic/DiagnosticSemaKinds.td @@ -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< diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index ae154aae20..679f4fefa2 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -157,6 +157,9 @@ static std::pair : Record->isPOD()) && Constructor->isDefaultConstructor()) CallsTrivialConstructor = true; + + if (CallsTrivialConstructor && !Record->hasTrivialDestructor()) + InDiag = diag::note_protected_by_variable_nontriv_destructor; } if (!CallsTrivialConstructor) diff --git a/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp b/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp index b41504488e..40b4c23841 100644 --- a/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp +++ b/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp @@ -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(); }