Diagnose duplicate C2x standard attributes.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 15 Nov 2019 23:22:41 +0000 (23:22 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 15 Nov 2019 23:22:41 +0000 (23:22 +0000)
commitd5fbe5e014bc9fc803604eec805392c21ff4da16
tree5a5b4f07e9d4923388a279c438f4ea282c9f6ead
parent2ab340fe17e7b5021c980badab9f5318d1517646
Diagnose duplicate C2x standard attributes.

For each of the attributes currently included in C2x, it has a
constraint that the attribute shall appear at most once in each
attribute list (attribute-list being what appear between a single [[
and ]]).

This patch implements that check.  As the corresponding check in the
C++ front end (cp_parser_check_std_attribute) makes violations into
errors, I made them into errors, with the same wording, for C as well.

There is an existing check in the case of the fallthrough attribute,
with a warning rather than an error, in attribute_fallthrough_p.  That
is more general, as it also covers __attribute__ ((fallthrough)) and
the case of [[fallthrough]] [[fallthrough]] (multiple attribute-lists
in a single attribute-specifier-sequence), which is not a constraint
violation.  To avoid some [[fallthrough, fallthrough]] being diagnosed
twice, the check I added avoids adding duplicate attributes to the
list.

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

gcc/c:
* c-parser.c (c_parser_std_attribute_specifier): Diagnose
duplicate standard attributes.

gcc/testsuite:
* gcc.dg/c2x-attr-deprecated-4.c, gcc.dg/c2x-attr-fallthrough-4.c,
gcc.dg/c2x-attr-maybe_unused-4.c: New tests.

From-SVN: r278324
gcc/c/ChangeLog
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c2x-attr-deprecated-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-4.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-4.c [new file with mode: 0644]