Improve checks on C2x fallthrough attribute.
authorJoseph Myers <joseph@codesourcery.com>
Fri, 15 Nov 2019 01:33:37 +0000 (01:33 +0000)
committerJoseph Myers <jsm28@gcc.gnu.org>
Fri, 15 Nov 2019 01:33:37 +0000 (01:33 +0000)
commitf8aea5e37d12e09fef68b854a190f71d6b39e11f
treeaf29d11914c8522b85aaac821765cf424cea24f3
parentd3cb8f004a3c1ea3de3d948d80f5faabadd1f0b0
Improve checks on C2x fallthrough attribute.

When adding C2x attribute support, some [[fallthrough]] support
appeared as a side-effect because of code for that attribute going
through separate paths from the normal attribute handling.

However, going through those paths without the normal attribute
handlers meant that certain checks, such as for the invalid usage
[[fallthrough()]], did not operate.  This patch improves checks by
adding this attribute to the standard attribute table, so that the
parser knows it expects no arguments, along with adding an explicit
check for "[[fallthrough]];" attribute-declarations at top level.  As
with other attributes, there are still cases where warnings should be
pedwarns because C2x constraints are violated, but this patch improves
the attribute handling.

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

gcc/c:
* c-decl.c (std_attribute_table): Add fallthrough.
* c-parser.c (c_parser_declaration_or_fndef): Diagnose fallthrough
attribute at top level.

gcc/c-family:
* c-attribs.c (handle_fallthrough_attribute): Remove static.
* c-common.h (handle_fallthrough_attribute): Declare.

gcc/testsuite:
* gcc.dg/c2x-attr-fallthrough-2.c,
gcc.dg/c2x-attr-fallthrough-3.c: New tests.

From-SVN: r278273
gcc/c-family/ChangeLog
gcc/c-family/c-attribs.c
gcc/c-family/c-common.h
gcc/c/ChangeLog
gcc/c/c-decl.c
gcc/c/c-parser.c
gcc/testsuite/ChangeLog
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c [new file with mode: 0644]
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-3.c [new file with mode: 0644]