[PATCH] D151683: [clang] Enable C++11-style attributes in all language modes

Aaron Ballman via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Mon Aug 7 12:12:42 PDT 2023


aaron.ballman added a comment.

In D151683#4566907 <https://reviews.llvm.org/D151683#4566907>, @eaeltsin wrote:

> Hi,
>
> Is it a known issue, that clang doesn't compile `void foo(char *argv[] [[maybe_unused]]) {}` ? The error is `error: 'maybe_unused' attribute cannot be applied to types`.
>
> https://godbolt.org/z/r9E81cWxh - clang fails, but gcc doesn't.
>
> It looks like there is a lot of oss code of the form `void foo(char *argv[] ATTRIBUTE_UNUSED)`, where `ATTRIBUTE_UNUSED` was configured to `__attribute__((unused))` before this change (thus compiled ok) and to `[[maybe_unused]]` after this change (thus started to break).

https://eel.is/c++draft/dcl.array#3.sentence-2 -- an attribute in that position appertains to the array type and `maybe_unused` cannot be applied to types in that way, so I believe Clang's behavior is correct. So I think the C++ attribute behavior is expected, but the change between `__attribute__` and `[[]]` may be catching folks off-guard.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D151683/new/

https://reviews.llvm.org/D151683



More information about the cfe-commits mailing list