summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPawel Wodnicki <pawel@32bitmicro.com>2012-12-05 23:48:42 +0000
committerPawel Wodnicki <pawel@32bitmicro.com>2012-12-05 23:48:42 +0000
commit9b65aea27ca3f915d8d197db494b4caccc745d3c (patch)
treedec0d6510ca24b2a95f8d75ef18088cc11646b3a
parentbefd16738b89241b794e5ebfd02d0511f7e39f90 (diff)
downloadclang-9b65aea27ca3f915d8d197db494b4caccc745d3c.tar.gz
clang-9b65aea27ca3f915d8d197db494b4caccc745d3c.tar.bz2
clang-9b65aea27ca3f915d8d197db494b4caccc745d3c.tar.xz
Merging r167766: into the 3.2 release branch.
Fix more try scoping bugs introduced by r167650. Introduces more clear scoping flags & flag combinations which should hopefully be more understandable. git-svn-id: https://llvm.org/svn/llvm-project/cfe/branches/release_32@169451 91177308-0d34-0410-b5e6-96231b3b80d8
-rw-r--r--include/clang/Sema/Scope.h11
-rw-r--r--lib/Parse/ParseStmt.cpp2
-rw-r--r--lib/Sema/IdentifierResolver.cpp13
-rw-r--r--test/CXX/basic/basic.scope/basic.scope.local/p2.cpp23
4 files changed, 38 insertions, 11 deletions
diff --git a/include/clang/Sema/Scope.h b/include/clang/Sema/Scope.h
index fa508cfc22..1329f97c2b 100644
--- a/include/clang/Sema/Scope.h
+++ b/include/clang/Sema/Scope.h
@@ -84,11 +84,18 @@ public:
/// TryScope - This is the scope of a C++ try statement.
TryScope = 0x1000,
+ /// CatchScope - This is the scope of a C++ catch statement.
+ CatchScope = 0x2000,
+
+ /// FnTryCatchScope - This is the scope for a function-level C++ try or
+ /// catch scope.
+ FnTryCatchScope = 0x4000,
+
/// FnTryScope - This is the scope of a function-level C++ try scope.
- FnTryScope = 0x3000,
+ FnTryScope = TryScope | FnTryCatchScope,
/// FnCatchScope - This is the scope of a function-level C++ catch scope.
- FnCatchScope = 0x4000
+ FnCatchScope = CatchScope | FnTryCatchScope
};
private:
/// The parent scope for this scope. This is null for the translation-unit
diff --git a/lib/Parse/ParseStmt.cpp b/lib/Parse/ParseStmt.cpp
index f604e038d2..5883115850 100644
--- a/lib/Parse/ParseStmt.cpp
+++ b/lib/Parse/ParseStmt.cpp
@@ -2197,7 +2197,7 @@ StmtResult Parser::ParseCXXCatchBlock(bool FnCatch) {
// The name in a catch exception-declaration is local to the handler and
// shall not be redeclared in the outermost block of the handler.
ParseScope CatchScope(this, Scope::DeclScope | Scope::ControlScope |
- (FnCatch ? Scope::FnCatchScope : 0));
+ (FnCatch ? Scope::FnCatchScope : Scope::CatchScope));
// exception-declaration is equivalent to '...' or a parameter-declaration
// without default arguments.
diff --git a/lib/Sema/IdentifierResolver.cpp b/lib/Sema/IdentifierResolver.cpp
index 00939151c6..7d5530442f 100644
--- a/lib/Sema/IdentifierResolver.cpp
+++ b/lib/Sema/IdentifierResolver.cpp
@@ -135,16 +135,13 @@ bool IdentifierResolver::isDeclInScope(Decl *D, DeclContext *Ctx,
// of the controlled statement.
//
assert(S->getParent() && "No TUScope?");
- if (S->getFlags() & Scope::FnTryScope)
- return S->getParent()->isDeclScope(D);
if (S->getParent()->getFlags() & Scope::ControlScope) {
- if (S->getParent()->getFlags() & Scope::FnCatchScope) {
- S = S->getParent();
- if (S->isDeclScope(D))
- return true;
- }
- return S->getParent()->isDeclScope(D);
+ S = S->getParent();
+ if (S->isDeclScope(D))
+ return true;
}
+ if (S->getFlags() & Scope::FnTryCatchScope)
+ return S->getParent()->isDeclScope(D);
}
return false;
}
diff --git a/test/CXX/basic/basic.scope/basic.scope.local/p2.cpp b/test/CXX/basic/basic.scope/basic.scope.local/p2.cpp
index 91e96b6b26..7c7b84d678 100644
--- a/test/CXX/basic/basic.scope/basic.scope.local/p2.cpp
+++ b/test/CXX/basic/basic.scope/basic.scope.local/p2.cpp
@@ -35,3 +35,26 @@ void func7() {
int i; // expected-error{{redefinition of 'i'}}
}
}
+
+void func8() {
+ int i;
+ try {
+ int i;
+ } catch (...) {
+ }
+}
+
+void func9() {
+ if (bool b = true)
+ try {
+ int b; // FIXME: this probably should be invalid, maybe
+ } catch (...) {
+ }
+}
+
+void func10() {
+ if (bool b = true)
+ if (true) {
+ int b; // FIXME: decide whether this is valid
+ }
+}