From: Argyrios Kyrtzidis Date: Tue, 21 Jul 2009 06:43:26 +0000 (+0000) Subject: Fix a crash that occurs in this C++ case: X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=f37006bc8a9d398d40d6ce329f023ed1a92fe484;p=clang Fix a crash that occurs in this C++ case: struct foo { static bool value; }; bool (foo::value); // crash because of parens git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@76538 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/include/clang/Parse/Parser.h b/include/clang/Parse/Parser.h index 677cd819ca..50145ae530 100644 --- a/include/clang/Parse/Parser.h +++ b/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/test/SemaCXX/nested-name-spec.cpp b/test/SemaCXX/nested-name-spec.cpp index 8fff8a2b2c..97f31033e8 100644 --- a/test/SemaCXX/nested-name-spec.cpp +++ b/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 {