This patch adds support for the C2x [[maybe_unused]] attribute, using the same handler as for GNU __attribute__ ((unused)).
As with other such attribute support, I think turning certain warnings into pedwarns for usage in cases where that is a constraint violation can be addressed later as a bug fix, as can the C2x constraint for
various standard attributes that they do not appear more than once inside a single [].
However, the warnings that appear in c2x-attr-maybe_unused-1.c (that the attribute is ignored on member declarations) need to remain as warnings not pedwarns, since C2x does permit the attribute there. (Or they could be silenced, on the basis that GCC doesn't have warnings for unused struct and union members so it's completely harmless that it's ignoring an attribute that might do something useful with another compiler that does have such warnings.)
Bootstrapped with no regressions on x86_64-pc-linux-gnu.
- c-decl.c (std_attribute_table): Add maybe_unused.
- gcc.dg/c2x-attr-maybe_unused-1.c, gcc.dg/c2x-attr-maybe_unused-2.c, gcc.dg/c2x-attr-maybe_unused-3.c: New tests.
7249f12b75a Support C2x [[maybe_unused]] attribute.
gcc/c/ChangeLog | 4 ++++
gcc/c/c-decl.c | 2 ++
gcc/testsuite/ChangeLog | 6 +++++
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-1.c | 31 ++++++++++++++++++++++++++
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-2.c | 25 +++++++++++++++++++++
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-3.c | 11 +++++++++
6 files changed, 79 insertions(+)