@@ -1100,31 +1100,31 @@ Parser::DeclGroupPtrTy Parser::ParseDeclOrFunctionDefInternal(
11001100 // C99 6.7.2.3p6: Handle "struct-or-union identifier;", "enum { X };"
11011101 // declaration-specifiers init-declarator-list[opt] ';'
11021102 if (Tok.is (tok::semi)) {
1103- auto GetAdjustedAttrsLoc = [&]() {
1104- auto TKind = DS. getTypeSpecType ();
1105- if (! DeclSpec::isDeclRep (TKind))
1106- return SourceLocation ();
1107-
1103+ // Suggest correct location to fix '[[attrib]] struct' to 'struct
1104+ // [[attrib]]'
1105+ SourceLocation CorrectLocationForAttributes{};
1106+ auto TKind = DS. getTypeSpecType ();
1107+ if ( DeclSpec::isDeclRep (TKind)) {
11081108 if (TKind == DeclSpec::TST_enum) {
11091109 const auto *ED = dyn_cast_or_null<EnumDecl>(DS.getRepAsDecl ());
11101110 if (ED) {
1111- if (ED->isScoped () && ED->getIdentifier ())
1112- return ED->getLocation ();
1113-
1114- const auto Begin = ED->getBraceRange ().getBegin ();
1115- if (Begin.isValid ())
1116- return Begin;
1111+ if (ED->getIdentifier ()) {
1112+ CorrectLocationForAttributes = ED->getLocation ();
1113+ } else {
1114+ const auto Begin = ED->getBraceRange ().getBegin ();
1115+ CorrectLocationForAttributes =
1116+ Begin.isValid () ? Begin : ED->getEndLoc ();
1117+ }
11171118 }
11181119 }
1119-
1120- const auto &Policy = Actions.getASTContext ().getPrintingPolicy ();
1121- unsigned Offset =
1122- StringRef (DeclSpec::getSpecifierName (TKind, Policy)).size ();
1123- return DS.getTypeSpecTypeLoc ().getLocWithOffset (Offset);
1124- };
1125-
1126- // Suggest correct location to fix '[[attrib]] struct' to 'struct [[attrib]]'
1127- SourceLocation CorrectLocationForAttributes = GetAdjustedAttrsLoc ();
1120+ if (CorrectLocationForAttributes.isInvalid ()) {
1121+ const auto &Policy = Actions.getASTContext ().getPrintingPolicy ();
1122+ unsigned Offset =
1123+ StringRef (DeclSpec::getSpecifierName (TKind, Policy)).size ();
1124+ CorrectLocationForAttributes =
1125+ DS.getTypeSpecTypeLoc ().getLocWithOffset (Offset);
1126+ }
1127+ }
11281128 ProhibitAttributes (Attrs, CorrectLocationForAttributes);
11291129 ConsumeToken ();
11301130 RecordDecl *AnonRecord = nullptr ;
0 commit comments