Fix more try scoping bugs introduced by r167650.
authorDavid Blaikie <dblaikie@gmail.com>
Mon, 12 Nov 2012 22:25:41 +0000 (22:25 +0000)
committerDavid Blaikie <dblaikie@gmail.com>
Mon, 12 Nov 2012 22:25:41 +0000 (22:25 +0000)
Introduces more clear scoping flags & flag combinations which should hopefully
be more understandable.

llvm-svn: 167766

clang/include/clang/Sema/Scope.h
clang/lib/Parse/ParseStmt.cpp
clang/lib/Sema/IdentifierResolver.cpp
clang/test/CXX/basic/basic.scope/basic.scope.local/p2.cpp

index fa508cfc22d9604c0ea06b0670415f2612031b26..1329f97c2bcf19921f1b36987a453220d5a801d6 100644 (file)
@@ -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
index f604e038d2adbab58d75ee2c7999112824f60260..58831158502022eae86e1ff686019b7c8cca6166 100644 (file)
@@ -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.
index 00939151c67394b523ee12407ed8de379e050c1b..7d5530442f48dac60098e9bc97802a94d0a59381 100644 (file)
@@ -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;
   }
index 91e96b6b2622fec395e05f69b787ea0e02759137..7c7b84d67823b0eacc551c48f33cfc4d5f665b8b 100644 (file)
@@ -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
+    }
+}