diff options
| author | Douglas Gregor <dgregor@apple.com> | 2011-06-15 03:23:34 +0000 |
|---|---|---|
| committer | Douglas Gregor <dgregor@apple.com> | 2011-06-15 03:23:34 +0000 |
| commit | 1778b030c0dc347a6b86f2331cf45bff33790dd5 (patch) | |
| tree | 7a592fa99ba4265bc7b82d039e67217c5e4f1656 | |
| parent | 0870debb8b311ce2b3b5fd79039b67f26bc7d057 (diff) | |
| download | bcm5719-llvm-1778b030c0dc347a6b86f2331cf45bff33790dd5.tar.gz bcm5719-llvm-1778b030c0dc347a6b86f2331cf45bff33790dd5.zip | |
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.
llvm-svn: 133037
| -rw-r--r-- | clang/include/clang/Basic/DiagnosticSemaKinds.td | 2 | ||||
| -rw-r--r-- | clang/lib/Sema/JumpDiagnostics.cpp | 3 | ||||
| -rw-r--r-- | clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp | 8 |
3 files changed, 9 insertions, 4 deletions
diff --git a/clang/include/clang/Basic/DiagnosticSemaKinds.td b/clang/include/clang/Basic/DiagnosticSemaKinds.td index ec237784942..ea736c0cd2e 100644 --- a/clang/include/clang/Basic/DiagnosticSemaKinds.td +++ b/clang/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/clang/lib/Sema/JumpDiagnostics.cpp b/clang/lib/Sema/JumpDiagnostics.cpp index ae154aae206..679f4fefa22 100644 --- a/clang/lib/Sema/JumpDiagnostics.cpp +++ b/clang/lib/Sema/JumpDiagnostics.cpp @@ -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) diff --git a/clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp b/clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp index b41504488e8..40b4c23841c 100644 --- a/clang/test/CXX/stmt.stmt/stmt.dcl/p3-0x.cpp +++ b/clang/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(); } |

