summaryrefslogtreecommitdiff
path: root/gcc/c-family/c-common.c
diff options
context:
space:
mode:
authorMarek Polacek <polacek@redhat.com>2020-11-06 12:33:53 -0500
committerMarek Polacek <polacek@redhat.com>2020-11-09 18:22:58 -0500
commit04126e46eb2d829d7b4149d394b667e878912cc8 (patch)
treed335d40d1f5e99dad16532ef1f34e6099465ff31 /gcc/c-family/c-common.c
parentd3fd75d869480044213553000d2c9dc236a4f7af (diff)
downloadgcc-04126e46eb2d829d7b4149d394b667e878912cc8.tar.gz
c++: DR 1914 - Allow duplicate standard attributes.
Following Joseph's change for C to allow duplicate C2x standard attributes <https://gcc.gnu.org/pipermail/gcc-patches/2020-October/557272.html>, this patch does a similar thing for C++. This is DR 1914, to be resolved by <wg21.link/p2156>, which is not part of the standard yet, but has wide support so looks like a shoo-in. The duplications now produce warnings instead, but only if the attribute wasn't specified via a macro. gcc/c-family/ChangeLog: DR 1914 * c-common.c (attribute_fallthrough_p): Tweak the warning message. gcc/cp/ChangeLog: DR 1914 * parser.c (cp_parser_check_std_attribute): Return bool. Add a location_t parameter. Return true if the attribute wasn't duplicated. Give a warning instead of an error. Check more attributes. (cp_parser_std_attribute_list): Don't add duplicated attributes to the list. Pass location to cp_parser_check_std_attribute. gcc/testsuite/ChangeLog: DR 1914 * c-c++-common/attr-fallthrough-2.c: Adjust dg-warning. * g++.dg/cpp0x/fallthrough2.C: Likewise. * g++.dg/cpp0x/gen-attrs-60.C: Turn dg-error into dg-warning. * g++.dg/cpp1y/attr-deprecated-2.C: Likewise. * g++.dg/cpp2a/attr-likely2.C: Adjust dg-warning. * g++.dg/cpp2a/nodiscard-once.C: Turn dg-error into dg-warning. * g++.dg/cpp0x/gen-attrs-72.C: New test.
Diffstat (limited to 'gcc/c-family/c-common.c')
-rw-r--r--gcc/c-family/c-common.c5
1 files changed, 3 insertions, 2 deletions
diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c
index d4d3228b8f6..29508bca97b 100644
--- a/gcc/c-family/c-common.c
+++ b/gcc/c-family/c-common.c
@@ -5752,9 +5752,10 @@ attribute_fallthrough_p (tree attr)
tree t = lookup_attribute ("fallthrough", attr);
if (t == NULL_TREE)
return false;
- /* This attribute shall appear at most once in each attribute-list. */
+ /* It is no longer true that "this attribute shall appear at most once in
+ each attribute-list", but we still give a warning. */
if (lookup_attribute ("fallthrough", TREE_CHAIN (t)))
- warning (OPT_Wattributes, "%<fallthrough%> attribute specified multiple "
+ warning (OPT_Wattributes, "attribute %<fallthrough%> specified multiple "
"times");
/* No attribute-argument-clause shall be present. */
else if (TREE_VALUE (t) != NULL_TREE)