diff options
author | Joseph Myers <joseph@codesourcery.com> | 2019-11-19 00:21:49 +0000 |
---|---|---|
committer | Joseph Myers <jsm28@gcc.gnu.org> | 2019-11-19 00:21:49 +0000 |
commit | 192961ff27503085946caaa92b2f57d291258858 (patch) | |
tree | eb264d8a06f3087a5902e4ba372c16cc11ed24e6 /gcc/c-family/c-common.c | |
parent | 95d4434f4777bda919474a06c4b071d3a5d4080e (diff) | |
download | gcc-192961ff27503085946caaa92b2f57d291258858.tar.gz |
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
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r-- | gcc/c-family/c-common.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 48811994f38..f779acc0387 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5702,7 +5702,15 @@ attribute_fallthrough_p (tree attr) { tree name = get_attribute_name (t); if (!is_attribute_p ("fallthrough", name)) - warning (OPT_Wattributes, "%qE attribute ignored", name); + { + if (!c_dialect_cxx () && get_attribute_namespace (t) == NULL_TREE) + /* The specifications of standard attributes in C mean + this is a constraint violation. */ + pedwarn (input_location, OPT_Wattributes, "%qE attribute ignored", + get_attribute_name (t)); + else + warning (OPT_Wattributes, "%qE attribute ignored", name); + } } return true; } |