@@ -5206,11 +5206,6 @@ auto Parser::parse_elaborated_enum_specifier(SpecifierAST*& yyast,
52065206 SourceLocation enumLoc;
52075207 if (!match (TokenKind::T_ENUM, enumLoc)) return false ;
52085208
5209- auto globalScopeGuard = Binder::ScopeGuard{&binder_};
5210- if (is_parsing_c ()) {
5211- setScope (globalScope_);
5212- }
5213-
52145209 NestedNameSpecifierAST* nestedNameSpecifier = nullptr ;
52155210 parse_optional_nested_name_specifier (
52165211 nestedNameSpecifier, NestedNameSpecifierContext::kDeclarative );
@@ -5251,8 +5246,9 @@ auto Parser::parse_elaborated_type_specifier(SpecifierAST*& yyast,
52515246 if (!parse_class_key (classLoc)) return false ;
52525247
52535248 auto globalScopeGuard = Binder::ScopeGuard{&binder_};
5249+
52545250 if (is_parsing_c ()) {
5255- setScope (globalScope_ );
5251+ setScope (getCurrentNonClassScope () );
52565252 }
52575253
52585254 List<AttributeSpecifierAST*>* attributes = nullptr ;
@@ -6408,8 +6404,9 @@ auto Parser::parse_enum_specifier(SpecifierAST*& yyast, DeclSpecs& specs)
64086404 if (!parse_enum_key (enumLoc, classLoc)) return false ;
64096405
64106406 auto globalScopeGuard = Binder::ScopeGuard{&binder_};
6407+
64116408 if (is_parsing_c ()) {
6412- setScope (globalScope_ );
6409+ setScope (getCurrentNonClassScope () );
64136410 }
64146411
64156412 List<AttributeSpecifierAST*>* attributes = nullptr ;
@@ -7700,8 +7697,9 @@ auto Parser::parse_class_specifier(ClassSpecifierAST*& yyast, DeclSpecs& specs)
77007697 if (!parse_class_key (classLoc)) return false ;
77017698
77027699 auto globalScopeGuard = Binder::ScopeGuard{&binder_};
7700+
77037701 if (is_parsing_c ()) {
7704- setScope (globalScope_ );
7702+ setScope (getCurrentNonClassScope () );
77057703 }
77067704
77077705 List<AttributeSpecifierAST*>* attributeList = nullptr ;
@@ -9634,6 +9632,15 @@ void Parser::completePendingFunctionDefinitions() {
96349632 }
96359633}
96369634
9635+ auto Parser::getCurrentNonClassScope () const -> Scope* {
9636+ for (auto current = scope (); current; current = current->parent ()) {
9637+ if (current->isClassOrNamespaceScope ()) continue ;
9638+ return current;
9639+ }
9640+
9641+ return globalScope_;
9642+ }
9643+
96379644auto Parser::scope () const -> Scope* { return binder_.scope (); }
96389645
96399646void Parser::setScope (Scope* scope) { binder_.setScope (scope); }
0 commit comments