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 | |
parent | 95d4434f4777bda919474a06c4b071d3a5d4080e (diff) | |
download | gcc-192961ff27503085946caaa92b2f57d291258858.zip gcc-192961ff27503085946caaa92b2f57d291258858.tar.gz gcc-192961ff27503085946caaa92b2f57d291258858.tar.bz2 |
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')
-rw-r--r-- | gcc/c-family/ChangeLog | 5 | ||||
-rw-r--r-- | gcc/c-family/c-common.c | 10 |
2 files changed, 14 insertions, 1 deletions
diff --git a/gcc/c-family/ChangeLog b/gcc/c-family/ChangeLog index c7420f6..e1b437b 100644 --- a/gcc/c-family/ChangeLog +++ b/gcc/c-family/ChangeLog @@ -1,3 +1,8 @@ +2019-11-19 Joseph Myers <joseph@codesourcery.com> + + * c-common.c (attribute_fallthrough_p): In C, use pedwarn not + warning for standard attributes mixed with fallthrough attributes. + 2019-11-15 Joseph Myers <joseph@codesourcery.com> * c-attribs.c (handle_fallthrough_attribute): Remove static. diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 4881199..f779acc 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; } |