diff --git a/clang/lib/Parse/ParseDeclCXX.cpp b/clang/lib/Parse/ParseDeclCXX.cpp --- a/clang/lib/Parse/ParseDeclCXX.cpp +++ b/clang/lib/Parse/ParseDeclCXX.cpp @@ -359,8 +359,11 @@ Tok.is(tok::l_brace) ? Tok.getLocation() : SourceLocation()); ParsedAttributes DeclAttrs(AttrFactory); - MaybeParseCXX11Attributes(DeclAttrs); - ParsedAttributes EmptyDeclSpecAttrs(AttrFactory); + ParsedAttributes DeclSpecAttrs(AttrFactory); + + while (MaybeParseCXX11Attributes(DeclAttrs) || + MaybeParseGNUAttributes(DeclSpecAttrs)) + ; if (Tok.isNot(tok::l_brace)) { // Reset the source range in DS, as the leading "extern" @@ -369,7 +372,7 @@ DS.SetRangeEnd(SourceLocation()); // ... but anyway remember that such an "extern" was seen. DS.setExternInLinkageSpec(true); - ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs, &DS); + ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs, &DS); return LinkageSpec ? Actions.ActOnFinishLinkageSpecification( getCurScope(), LinkageSpec, SourceLocation()) : nullptr; @@ -411,7 +414,7 @@ default: ParsedAttributes DeclAttrs(AttrFactory); MaybeParseCXX11Attributes(DeclAttrs); - ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs); + ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs); continue; } diff --git a/clang/test/Parser/cxx-attributes.cpp b/clang/test/Parser/cxx-attributes.cpp --- a/clang/test/Parser/cxx-attributes.cpp +++ b/clang/test/Parser/cxx-attributes.cpp @@ -3,6 +3,8 @@ // GH#58229 - rejects-valid __attribute__((__visibility__("default"))) [[nodiscard]] int f(); [[nodiscard]] __attribute__((__visibility__("default"))) int f(); +extern "C" __attribute__((__visibility__("default"))) [[nodiscard]] +int g() { return 32; } class c { virtual void f1(const char* a, ...)