diff options
author | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-04-27 20:27:31 +0000 |
---|---|---|
committer | Sebastian Redl <sebastian.redl@getdesigned.at> | 2009-04-27 20:27:31 +0000 |
commit | 972041f45bdf8df7ea447221292d7827466ba94b (patch) | |
tree | a0ab42cb23efe594d91c2fa76372f585823da1c1 /lib/Sema/JumpDiagnostics.cpp | |
parent | b81c17092039f39be60e9656a37cffbdf2e2c783 (diff) |
Improve validation of C++ exception handling: diagnose throwing incomplete types and jumps into protected try-catch scopes.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@70242 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/JumpDiagnostics.cpp')
-rw-r--r-- | lib/Sema/JumpDiagnostics.cpp | 24 |
1 files changed, 22 insertions, 2 deletions
diff --git a/lib/Sema/JumpDiagnostics.cpp b/lib/Sema/JumpDiagnostics.cpp index 20473e4306..ae863f2df1 100644 --- a/lib/Sema/JumpDiagnostics.cpp +++ b/lib/Sema/JumpDiagnostics.cpp @@ -15,6 +15,7 @@ #include "Sema.h" #include "clang/AST/Expr.h" #include "clang/AST/StmtObjC.h" +#include "clang/AST/StmtCXX.h" using namespace clang; namespace { @@ -115,7 +116,6 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { // FIXME: diagnose jumps past initialization: required in C++, warning in C. // goto L; int X = 4; L: ; - // FIXME: what about jumps into C++ catch blocks, what are the rules? // If this is a declstmt with a VLA definition, it defines a scope from here // to the end of the containing context. @@ -184,7 +184,27 @@ void JumpScopeChecker::BuildScopeInformation(Stmt *S, unsigned ParentScope) { BuildScopeInformation(AS->getSynchBody(), Scopes.size()-1); continue; } - + + // Disallow jumps into any part of a C++ try statement. This is pretty + // much the same as for Obj-C. + if (CXXTryStmt *TS = dyn_cast<CXXTryStmt>(SubStmt)) { + Scopes.push_back(GotoScope(ParentScope, diag::note_protected_by_cxx_try, + TS->getSourceRange().getBegin())); + if (Stmt *TryBlock = TS->getTryBlock()) + BuildScopeInformation(TryBlock, Scopes.size()-1); + + // Jump from the catch into the try is not allowed either. + for(unsigned I = 0, E = TS->getNumHandlers(); I != E; ++I) { + CXXCatchStmt *CS = TS->getHandler(I); + Scopes.push_back(GotoScope(ParentScope, + diag::note_protected_by_cxx_catch, + CS->getSourceRange().getBegin())); + BuildScopeInformation(CS->getHandlerBlock(), Scopes.size()-1); + } + + continue; + } + // Recursively walk the AST. BuildScopeInformation(SubStmt, ParentScope); } |