diff --git a/clang/include/clang/Parse/Parser.h b/clang/include/clang/Parse/Parser.h index 677cd819ca27..50145ae5300b 100644 --- a/clang/include/clang/Parse/Parser.h +++ b/clang/include/clang/Parse/Parser.h @@ -1080,17 +1080,22 @@ private: class DeclaratorScopeObj { Parser &P; CXXScopeSpec &SS; + bool EnteredScope; public: - DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) : P(p), SS(ss) {} + DeclaratorScopeObj(Parser &p, CXXScopeSpec &ss) + : P(p), SS(ss), EnteredScope(false) {} void EnterDeclaratorScope() { - if (SS.isSet()) - P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS); + assert(SS.isSet() && "C++ scope was not set!"); + P.Actions.ActOnCXXEnterDeclaratorScope(P.CurScope, SS); + EnteredScope = true; } ~DeclaratorScopeObj() { - if (SS.isSet()) + if (EnteredScope) { + assert(SS.isSet() && "C++ scope was cleared ?"); P.Actions.ActOnCXXExitDeclaratorScope(P.CurScope, SS); + } } }; diff --git a/clang/test/SemaCXX/nested-name-spec.cpp b/clang/test/SemaCXX/nested-name-spec.cpp index 8fff8a2b2cbc..97f31033e8ab 100644 --- a/clang/test/SemaCXX/nested-name-spec.cpp +++ b/clang/test/SemaCXX/nested-name-spec.cpp @@ -172,7 +172,10 @@ X::X() : a(5) { } // expected-error{{use of undeclared identifier 'X'}} \ // expected-error{{C++ requires a type specifier for all declarations}} \ // expected-error{{only constructors take base initializers}} - +struct foo_S { + static bool value; +}; +bool (foo_S::value); namespace somens {