Skip to content

[Clang] disallow attributes on void parameters #124920

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 23 commits into from
Feb 11, 2025
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
bd731e4
[Clang] disallow attributes on void parameters
a-tarasyuk Jan 29, 2025
063f767
remove unnecessary name check
a-tarasyuk Jan 29, 2025
3f34315
use empty instead of size
a-tarasyuk Jan 29, 2025
9919006
move handling of void parameter attributes to sema decl
a-tarasyuk Jan 30, 2025
c76ad55
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Jan 30, 2025
35e67d1
Merge branch 'main' into fix/108819
a-tarasyuk Jan 30, 2025
8abec1e
remove useless hasAttrs condition
a-tarasyuk Jan 31, 2025
cb11b95
update release notes
a-tarasyuk Jan 31, 2025
58d5021
fix formatting
a-tarasyuk Jan 31, 2025
afe40bf
Merge branch 'fix/108819' of https://github.com/a-tarasyuk/llvm-proje…
a-tarasyuk Jan 31, 2025
8491f87
fix formatting
a-tarasyuk Jan 31, 2025
8dc35b4
exclude void parameters in pragma attrs push diagnostics
a-tarasyuk Feb 3, 2025
114284b
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Feb 3, 2025
54a2172
remove identifier check
a-tarasyuk Feb 4, 2025
3a2b9d1
use auto instead of explicit type
a-tarasyuk Feb 4, 2025
da7d009
move invalid attribute handling on void parameters to SemaType
a-tarasyuk Feb 4, 2025
c77d82d
add additional test cases
a-tarasyuk Feb 4, 2025
6b0a473
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Feb 4, 2025
3c358e5
Merge branch 'main' of https://github.com/llvm/llvm-project into fix/…
a-tarasyuk Feb 4, 2025
85b17fa
Merge branch 'main' into fix/108819
a-tarasyuk Feb 5, 2025
4b511ba
Merge branch 'main' into fix/108819
a-tarasyuk Feb 6, 2025
3f05665
Merge branch 'main' into fix/108819
a-tarasyuk Feb 7, 2025
0324a4c
Merge branch 'main' into fix/108819
a-tarasyuk Feb 10, 2025
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
2 changes: 2 additions & 0 deletions clang/docs/ReleaseNotes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,8 @@ Removed Compiler Flags
Attribute Changes in Clang
--------------------------

- Clang now disallows the use of attributes on void parameters. (#GH108819)

Improvements to Clang's diagnostics
-----------------------------------

Expand Down
6 changes: 6 additions & 0 deletions clang/lib/Parse/ParseDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7986,6 +7986,12 @@ void Parser::ParseParameterDeclarationClause(
if (getLangOpts().HLSL)
MaybeParseHLSLAnnotations(DS.getAttributes());

if (ParmDeclarator.getDeclarationAttributes().size() &&
ParmDeclarator.getDeclSpec().getTypeSpecType() == DeclSpec::TST_void) {
SourceRange AttrRange = ParmDeclarator.getDeclarationAttributes().Range;
Diag(AttrRange.getBegin(), diag::err_attributes_not_allowed) << AttrRange;
}

if (Tok.is(tok::kw_requires)) {
// User tried to define a requires clause in a parameter declaration,
// which is surely not a function declaration.
Expand Down
9 changes: 9 additions & 0 deletions clang/test/Parser/cxx0x-attributes.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -453,3 +453,12 @@ namespace P2361 {
}

alignas(int) struct AlignAsAttribute {}; // expected-error {{misplaced attributes; expected attributes here}}

namespace GH108819 {
void a([[maybe_unused]] void) {} // expected-error {{an attribute list cannot appear here}} \
// expected-warning {{use of the 'maybe_unused' attribute is a C++17 extension}}
void b([[deprecated]] void) {} // expected-error {{an attribute list cannot appear here}} \
// expected-warning {{use of the 'deprecated' attribute is a C++14 extension}}
void c([[clang::lifetimebound]] void) {} // expected-error {{an attribute list cannot appear here}}
void d([[clang::annotate("a", "b", 1)]] void) {} // expected-error {{an attribute list cannot appear here}}
}