Support C2x [[maybe_unused]] attribute.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 15 Nov 2019 18:39:35 +0000 (18:39 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 15 Nov 2019 18:39:35 +0000 (18:39 +0000)
commit97cc11871e39888bfca4ed4bf09fa09fe0916266
treec0b8023fcc02ba1d811307c9478303e4dd99badc
parenta91eb2341f6a0ae5700e0f09ccb8b561f35cb0f8
Support C2x [[maybe_unused]] attribute.

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.

gcc/c:
* c-decl.c (std_attribute_table): Add maybe_unused.

gcc/testsuite:
* 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.

From-SVN: r278310
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-1.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-3.c [new file with mode: 0644]