From ddbf4e0c2c35f98efa7fe6b3e235dc39c7f5af73 Mon Sep 17 00:00:00 2001 From: Douglas Gregor Date: Tue, 21 Jul 2009 18:59:28 +0000 Subject: [PATCH] Make Sema::ActOnCXXEnterDeclaratorScope robust against failures to compute the declaration context, as occurs with out-of-line class template member definitions. llvm-svn: 76622 --- clang/include/clang/Parse/Parser.h | 3 ++- clang/lib/Sema/SemaCXXScopeSpec.cpp | 11 ++++++++--- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 18f61e7..bebc874 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1089,7 +1089,8 @@ private: assert(!EnteredScope && "Already entered the scope!"); assert(SS.isSet() && "C++ scope was not set!"); P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS); - EnteredScope = true; + if (!SS.isInvalid()) + EnteredScope = true; } ~DeclaratorScopeObj() { diff --git a/clang/lib/Sema/SemaCXXScopeSpec.cpp b/clang/lib/Sema/SemaCXXScopeSpec.cpp index a14bcd5..aad6e6d 100644 --- a/clang/lib/Sema/SemaCXXScopeSpec.cpp +++ b/clang/lib/Sema/SemaCXXScopeSpec.cpp @@ -286,7 +286,10 @@ Sema::CXXScopeTy *Sema::ActOnCXXNestedNameSpecifier(Scope *S, /// The 'SS' should be a non-empty valid CXXScopeSpec. void Sema::ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { assert(SS.isSet() && "Parser passed invalid CXXScopeSpec."); - EnterDeclaratorContext(S, computeDeclContext(SS)); + if (DeclContext *DC = computeDeclContext(SS)) + EnterDeclaratorContext(S, DC); + else + const_cast(SS).setScopeRep(0); } /// ActOnCXXExitDeclaratorScope - Called when a declarator that previously @@ -296,6 +299,8 @@ void Sema::ActOnCXXEnterDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { /// defining scope. void Sema::ActOnCXXExitDeclaratorScope(Scope *S, const CXXScopeSpec &SS) { assert(SS.isSet() && "Parser passed invalid CXXScopeSpec."); - assert(S->getEntity() == computeDeclContext(SS) && "Context imbalance!"); - ExitDeclaratorContext(S); + assert((SS.isInvalid() || S->getEntity() == computeDeclContext(SS)) && + "Context imbalance!"); + if (!SS.isInvalid()) + ExitDeclaratorContext(S); } -- 2.7.4