Change some bad uses of C2x attributes into pedwarns

Programming / Compilers / GCC - jsm28 [138bc75d-0d04-0410-961f-82ee72b054a4] - 19 November 2019 00:21 EST

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.

baacd859bdd Change some bad uses of C2x attributes into pedwarns.
gcc/c-family/ChangeLog | 5 ++
gcc/c-family/c-common.c | 10 +++-
gcc/c/ChangeLog | 8 +++
gcc/c/c-decl.c | 10 +++-
gcc/c/c-parser.c | 78 +++++++++++++++-----------
gcc/testsuite/ChangeLog | 9 +++
gcc/testsuite/gcc.dg/c2x-attr-deprecated-2.c | 6 +-
gcc/testsuite/gcc.dg/c2x-attr-deprecated-4.c | 2 +-
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-2.c | 2 +-
gcc/testsuite/gcc.dg/c2x-attr-fallthrough-5.c | 30 ++++++++++
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-2.c | 6 +-
gcc/testsuite/gcc.dg/c2x-attr-maybe_unused-4.c | 2 +-
gcc/testsuite/gcc.dg/c2x-attr-syntax-5.c | 56 ++++++++++++++++++
13 files changed, 180 insertions(+), 44 deletions(-)

Upstream: gcc.gnu.org


  • Share