llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang Author: Oleksandr T. (a-tarasyuk) <details> <summary>Changes</summary> Fixes #<!-- -->108819 --- This PR introduces diagnostics to disallow the use of attributes on void parameters ```cpp void f([[deprecated]] void) {} ``` --- Full diff: https://github.com/llvm/llvm-project/pull/124920.diff 3 Files Affected: - (modified) clang/docs/ReleaseNotes.rst (+2) - (modified) clang/lib/Parse/ParseDecl.cpp (+7) - (modified) clang/test/Parser/cxx0x-attributes.cpp (+9) ``````````diff diff --git a/clang/docs/ReleaseNotes.rst b/clang/docs/ReleaseNotes.rst index 7fafe2807bd388..0c87e52007d546 100644 --- a/clang/docs/ReleaseNotes.rst +++ b/clang/docs/ReleaseNotes.rst @@ -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 ----------------------------------- diff --git a/clang/lib/Parse/ParseDecl.cpp b/clang/lib/Parse/ParseDecl.cpp index f136d5007e8a5f..0b88dd4449b1e2 100644 --- a/clang/lib/Parse/ParseDecl.cpp +++ b/clang/lib/Parse/ParseDecl.cpp @@ -7986,6 +7986,13 @@ void Parser::ParseParameterDeclarationClause( if (getLangOpts().HLSL) MaybeParseHLSLAnnotations(DS.getAttributes()); + if (ParmDeclarator.getIdentifier() == nullptr && + 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. diff --git a/clang/test/Parser/cxx0x-attributes.cpp b/clang/test/Parser/cxx0x-attributes.cpp index fad3010c98b9c2..13fcdd142fa841 100644 --- a/clang/test/Parser/cxx0x-attributes.cpp +++ b/clang/test/Parser/cxx0x-attributes.cpp @@ -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}} +} `````````` </details> https://github.com/llvm/llvm-project/pull/124920 _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits