Change some bad uses of C2x attributes into pedwarns.
authorJoseph Myers <joseph@codesourcery.com>
Tue, 19 Nov 2019 00:21:49 +0000 (00:21 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Tue, 19 Nov 2019 00:21:49 +0000 (00:21 +0000)
commit192961ff27503085946caaa92b2f57d291258858
treeeb264d8a06f3087a5902e4ba372c16cc11ed24e6
parent95d4434f4777bda919474a06c4b071d3a5d4080e
Change some bad uses of C2x attributes into pedwarns.

Certain bad uses of C2x standard attributes (that is, attributes
inside [[]] with only a name but no namespace specified) are
constraint violations, and so should be diagnosed with a pedwarn (or
error) where GCC currently uses a warning.  This patch implements this
in some cases (not yet for attributes used on types, nor for some bad
uses of fallthrough attributes).  Specifically, this applies to
unknown standard attributes (taking care not to pedwarn for nodiscard,
which is known but not implemented for C), and to all currently
implemented standard attributes in attribute declarations (including
when mixed with fallthrough) and on statements.

Bootstrapped with no regressions on x86_64-pc-linux-gnu.

gcc/c:
* c-decl.c (c_warn_unused_attributes): Use pedwarn not warning for
standard attributes.
* c-parser.c (c_parser_std_attribute): Take argument for_tm.  Use
pedwarn for unknown standard attributes and return error_mark_node
for them.

gcc/c-family:
* c-common.c (attribute_fallthrough_p): In C, use pedwarn not
warning for standard attributes mixed with fallthrough attributes.

gcc/testsuite:
* gcc.dg/c2x-attr-fallthrough-5.c, gcc.dg/c2x-attr-syntax-5.c: New
tests.
* gcc.dg/c2x-attr-deprecated-2.c, gcc.dg/c2x-attr-deprecated-4.c,
gcc.dg/c2x-attr-fallthrough-2.c, gcc.dg/c2x-attr-maybe_unused-2.c,
gcc.dg/c2x-attr-maybe_unused-4.c: Expect errors in place of some
warnings.

From-SVN: r278428
13 files changed:
gcc/c-family/ChangeLog
gcc/c-family/c-common.c
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c2x-attr-deprecated-2.c
gcc/testsuite/gcc.dg/c2x-attr-deprecated-4.c
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-5.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-2.c
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-4.c
gcc/testsuite/gcc.dg/c2x-attr-syntax-5.c [new file with mode: 0644]