diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index 58cd3909c206..2ce7499b25af 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -4591,11 +4591,18 @@ void Sema::ActOnBlockError(SourceLocation CaretLoc, Scope *CurScope) { // Ensure that CurBlock is deleted. llvm::OwningPtr CC(CurBlock); + // Before popping CurBlock, set ActiveScope to this scope's function + // or block parent. + ActiveScope = CurBlock->TheScope->getParent(); + while (ActiveScope && + ((ActiveScope->getFlags() & (Scope::FnScope | Scope::BlockScope)) == 0)) + ActiveScope = ActiveScope->getParent(); + // Pop off CurBlock, handle nested blocks. CurBlock = CurBlock->PrevBlockInfo; // FIXME: Delete the ParmVarDecl objects as well??? - + } /// ActOnBlockStmtExpr - This is called when the body of a block statement @@ -4608,8 +4615,12 @@ Sema::ExprResult Sema::ActOnBlockStmtExpr(SourceLocation CaretLoc, StmtTy *body, PopDeclContext(); - // Before poping CurBlock, set ActiveScope to this scopes parent. + // Before popping CurBlock, set ActiveScope to this scope's function + // or block parent. ActiveScope = CurBlock->TheScope->getParent(); + while (ActiveScope && + ((ActiveScope->getFlags() & (Scope::FnScope | Scope::BlockScope)) == 0)) + ActiveScope = ActiveScope->getParent(); // Pop off CurBlock, handle nested blocks. CurBlock = CurBlock->PrevBlockInfo;