Skip to content

Parse: handle another case of invalid handling for attributes #5869

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jan 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 7 additions & 4 deletions clang/lib/Parse/ParseDeclCXX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -359,8 +359,11 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) {
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"
Expand All @@ -369,7 +372,7 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) {
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;
Expand Down Expand Up @@ -411,7 +414,7 @@ Decl *Parser::ParseLinkage(ParsingDeclSpec &DS, DeclaratorContext Context) {
default:
ParsedAttributes DeclAttrs(AttrFactory);
MaybeParseCXX11Attributes(DeclAttrs);
ParseExternalDeclaration(DeclAttrs, EmptyDeclSpecAttrs);
ParseExternalDeclaration(DeclAttrs, DeclSpecAttrs);
continue;
}

Expand Down
2 changes: 2 additions & 0 deletions clang/test/Parser/cxx-attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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, ...)
Expand Down