From patchwork Fri Nov 6 19:06:11 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 1395873 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=pass (p=none dis=none) header.from=gcc.gnu.org Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=j2pSgubx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4CSVHD1mZCz9sSf for ; Sat, 7 Nov 2020 06:06:30 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D4D333850427; Fri, 6 Nov 2020 19:06:27 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org D4D333850427 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1604689587; bh=CajlLNTEmATJ/YId+U1b7quzo6z2w0pQ890IrLLg1Fk=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=j2pSgubx9TgniACyquRxUrJqd4eD5OrpTKr8MeanS1hVlfmvsIiV7ArsT8cNbgapc hbEIA+g3S69NAFBSo4CKO7ilGJ/99VIjGL6DTHdLA8WNv9+ltT20+wh1Knnz/p1daR 8tkT0BXxE0F6cUsYcCvNvLlnnDHQ61uJEXoKqA+Y= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [63.128.21.124]) by sourceware.org (Postfix) with ESMTP id 4059B3857839 for ; Fri, 6 Nov 2020 19:06:24 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 4059B3857839 Received: from mimecast-mx01.redhat.com (mimecast-mx01.redhat.com [209.132.183.4]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-528-S3hYsP4iMuSSxD7J3PqIzw-1; Fri, 06 Nov 2020 14:06:17 -0500 X-MC-Unique: S3hYsP4iMuSSxD7J3PqIzw-1 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id B79158030A7 for ; Fri, 6 Nov 2020 19:06:16 +0000 (UTC) Received: from pdp-11.hsd1.ma.comcast.net (ovpn-117-111.rdu2.redhat.com [10.10.117.111]) by smtp.corp.redhat.com (Postfix) with ESMTP id 5734B6EF6D; Fri, 6 Nov 2020 19:06:16 +0000 (UTC) To: GCC Patches , Jason Merrill Subject: [PATCH] c++: DR 1914 - Allow duplicate standard attributes. Date: Fri, 6 Nov 2020 14:06:11 -0500 Message-Id: <20201106190611.911508-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, KAM_SHORT, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H5, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-Patchwork-Original-From: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" Following Joseph's change for C to allow duplicate C2x standard attributes , this patch does a similar thing for C++. This is DR 1914, to be resolved by , which is not part of the standard yet, but has a wide support so look like a shoo-in. Some duplications still produce warnings; I didn't change that because a warning might be desirable. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? gcc/c-family/ChangeLog: DR 1914 * c-common.c (attribute_fallthrough_p): Update comment. gcc/cp/ChangeLog: DR 1914 * parser.c (cp_parser_check_std_attribute): Remove. (cp_parser_std_attribute_list): Don't call it. gcc/testsuite/ChangeLog: DR 1914 * g++.dg/cpp0x/gen-attrs-60.C: Remove dg-error. * g++.dg/cpp2a/nodiscard-once.C: Likewise. * g++.dg/cpp1y/attr-deprecated-2.C: Likewise. * g++.dg/cpp0x/gen-attrs-72.C: New test. --- gcc/c-family/c-common.c | 3 +- gcc/cp/parser.c | 27 ------------ gcc/testsuite/g++.dg/cpp0x/gen-attrs-60.C | 2 +- gcc/testsuite/g++.dg/cpp0x/gen-attrs-72.C | 42 +++++++++++++++++++ .../g++.dg/cpp1y/attr-deprecated-2.C | 2 +- gcc/testsuite/g++.dg/cpp2a/nodiscard-once.C | 2 +- 6 files changed, 47 insertions(+), 31 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp0x/gen-attrs-72.C base-commit: 05f1883cfd041adba5f595e97118100b6e00a524 diff --git a/gcc/c-family/c-common.c b/gcc/c-family/c-common.c index 232a4797c09..03d8fec9936 100644 --- a/gcc/c-family/c-common.c +++ b/gcc/c-family/c-common.c @@ -5751,7 +5751,8 @@ 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, "% attribute specified multiple " "times"); diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c index 6e7b982f073..0567646fbe2 100644 --- a/gcc/cp/parser.c +++ b/gcc/cp/parser.c @@ -27269,32 +27269,6 @@ cp_parser_std_attribute (cp_parser *parser, tree attr_ns) return attribute; } -/* Check that the attribute ATTRIBUTE appears at most once in the - attribute-list ATTRIBUTES. This is enforced for noreturn (7.6.3), - nodiscard, and deprecated (7.6.5). Note that - carries_dependency (7.6.4) isn't implemented yet in GCC. */ - -static void -cp_parser_check_std_attribute (tree attributes, tree attribute) -{ - if (attributes) - { - tree name = get_attribute_name (attribute); - if (is_attribute_p ("noreturn", name) - && lookup_attribute ("noreturn", attributes)) - error ("attribute % can appear at most once " - "in an attribute-list"); - else if (is_attribute_p ("deprecated", name) - && lookup_attribute ("deprecated", attributes)) - error ("attribute % can appear at most once " - "in an attribute-list"); - else if (is_attribute_p ("nodiscard", name) - && lookup_attribute ("nodiscard", attributes)) - error ("attribute % can appear at most once " - "in an attribute-list"); - } -} - /* Parse a list of standard C++-11 attributes. attribute-list: @@ -27317,7 +27291,6 @@ cp_parser_std_attribute_list (cp_parser *parser, tree attr_ns) break; if (attribute != NULL_TREE) { - cp_parser_check_std_attribute (attributes, attribute); TREE_CHAIN (attribute) = attributes; attributes = attribute; } diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-60.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-60.C index cb0c31ec63f..4e905c394ca 100644 --- a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-60.C +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-60.C @@ -1,4 +1,4 @@ // PR c++/60365 // { dg-do compile { target c++11 } } -void func [[noreturn, noreturn]] (); // { dg-error "at most once" } +void func [[noreturn, noreturn]] (); diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-72.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-72.C new file mode 100644 index 00000000000..0cb874b6191 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-72.C @@ -0,0 +1,42 @@ +// DR 1914 - Duplicate standard attributes +// { dg-do compile { target c++11 } } + +[[noreturn, noreturn]] void fn0(); +[[noreturn]] [[noreturn]] void fn1(); +[[deprecated, deprecated]] void fn2(); +[[deprecated]] [[deprecated]] void fn3(); +[[maybe_unused]] [[maybe_unused]] int fn4(); +[[maybe_unused, maybe_unused]] int fn5(); +[[nodiscard]] [[nodiscard]] int fn6(); +[[nodiscard, nodiscard]] int fn7(); + +struct E { }; +struct A { + [[no_unique_address]] [[no_unique_address]] E e; +}; +struct B { + [[no_unique_address, no_unique_address]] E e; +}; + +int +f (int n) +{ + switch (n) + { + case 1: + [[fallthrough, fallthrough]]; // { dg-warning "attribute specified multiple times" } + case 2: + [[fallthrough]] [[fallthrough]]; // { dg-warning "attribute specified multiple times" } + case 3: + return 15; + } + + if (n == 10) + [[likely]] [[likely]] return 42; // { dg-warning "ignoring attribute" } + else if (n == 11) + [[unlikely]] [[unlikely]] return 10; // { dg-warning "ignoring attribute" } + else if (n == 12) + [[likely, likely]] return 42; // { dg-warning "ignoring attribute" } + else + [[unlikely, unlikely]] return 0; // { dg-warning "ignoring attribute" } +} diff --git a/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-2.C b/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-2.C index 12c75c7ba73..1669bbf5376 100644 --- a/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-2.C +++ b/gcc/testsuite/g++.dg/cpp1y/attr-deprecated-2.C @@ -1,4 +1,4 @@ // PR c++/60365 // { dg-do compile { target c++14 } } -void func [[deprecated, deprecated]] (); // { dg-error "at most once" } +void func [[deprecated, deprecated]] (); diff --git a/gcc/testsuite/g++.dg/cpp2a/nodiscard-once.C b/gcc/testsuite/g++.dg/cpp2a/nodiscard-once.C index c810fd0daad..da992f9f0c7 100644 --- a/gcc/testsuite/g++.dg/cpp2a/nodiscard-once.C +++ b/gcc/testsuite/g++.dg/cpp2a/nodiscard-once.C @@ -2,7 +2,7 @@ /* { dg-do compile { target c++20 } } */ /* { dg-options "-O -ftrack-macro-expansion=0" } */ -[[nodiscard, nodiscard]] int check1 (void); /* { dg-error "nodiscard\[^\n\r]*can appear at most once" } */ +[[nodiscard, nodiscard]] int check1 (void); void test (void)