From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 6D89B3858D32 for ; Mon, 29 Aug 2022 17:32:35 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 6D89B3858D32 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1661794354; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=/eAs7VCD54GAtK2ll9QA3Qod61/ZwrDsL0A+GmrdTXI=; b=G9t9UPIe0DlvPvmOXdp66ilxsdsJA1Xlu2tgYMHozszUGArbLFa37dDLhRX2a6aIzAhynq 17dPYAu3D7PXrRnz8ppD3FoxdMoQBsCPNk1JWbO55W6HFX4d7MJ/VRY6kdiJvjz62K53s4 Rgr1bG751yoC4zdFMzsYJBqSTSXfl0Q= Received: from mail-qv1-f70.google.com (mail-qv1-f70.google.com [209.85.219.70]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_128_GCM_SHA256) id us-mta-142-Z2Oc_Ys8PBeiC8dC6wPXgg-1; Mon, 29 Aug 2022 13:32:32 -0400 X-MC-Unique: Z2Oc_Ys8PBeiC8dC6wPXgg-1 Received: by mail-qv1-f70.google.com with SMTP id cz3-20020a056214088300b00498f11a6d8aso4694809qvb.11 for ; Mon, 29 Aug 2022 10:32:32 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc; bh=/eAs7VCD54GAtK2ll9QA3Qod61/ZwrDsL0A+GmrdTXI=; b=3Ez7iuTghMvJ7f3T2jdGuxZOEPupgTW26NT5FRDSy8j+ogE6DxfW8Yd/ncQSJgE/jb 5xTvANS8+JvPphSRBJasZaEUflbQJsyfngvmvI7aoR+DwfTfOzqG4tmMNM4FzvjP52G5 t+o93664tmHFgApQ0nIBz4J0jD66eY0csjGgOb2ne6YufMuvx/RrRPTLn7wVmoMizXBz MYVctzQd3HK2hSfhyOjjbiEA7vNgk1vuRLVZiPbOCScFAQQSfN6kPmu5xnTxQ+tqy/aF NC0XgSs+IDYoFxnR2QzhSLgIbDbGREhe0b0DFWQjsxBKvlWiuThS4LYDnU67+3qKelOL XJfA== X-Gm-Message-State: ACgBeo3D+iN1QQ7vF2KgSjcp8zxUr8lkgdGlKRNjFjFwlmuoe+4Q7gx1 tTdfZR4JFbK6IgMFbvyUOdD/HNJw5gL+ipR4lLa3qGdnCbsxnMafeW/C7Q7GXaAHnIXmc4lhNSX pS/0+8aSOQLMZSLKz/g== X-Received: by 2002:a05:620a:bc5:b0:6b6:64e9:2617 with SMTP id s5-20020a05620a0bc500b006b664e92617mr8845345qki.378.1661794352104; Mon, 29 Aug 2022 10:32:32 -0700 (PDT) X-Google-Smtp-Source: AA6agR46D32lce5StMEZzFykHTt3xQuyGBBhedqKrY8bBmB4TISahZCTs36mDcCJOs+wYr6OmCyg/g== X-Received: by 2002:a05:620a:bc5:b0:6b6:64e9:2617 with SMTP id s5-20020a05620a0bc500b006b664e92617mr8845326qki.378.1661794351750; Mon, 29 Aug 2022 10:32:31 -0700 (PDT) Received: from [192.168.1.101] (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id w14-20020ac843ce000000b00343681ee2e2sm5326696qtn.35.2022.08.29.10.32.30 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Mon, 29 Aug 2022 10:32:31 -0700 (PDT) Message-ID: <95c29538-938d-1e24-95ed-3b2a402980d4@redhat.com> Date: Mon, 29 Aug 2022 13:32:29 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.13.0 Subject: Re: [PATCH] c++: Fix C++11 attribute propagation [PR106712] To: Marek Polacek , GCC Patches References: <20220826230150.328756-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20220826230150.328756-1-polacek@redhat.com> X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Language: en-US Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit X-Spam-Status: No, score=-12.6 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,GIT_PATCH_0,NICE_REPLY_A,RCVD_IN_DNSWL_NONE,SPF_HELO_NONE,SPF_NONE,TXREP,T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on server2.sourceware.org List-Id: On 8/26/22 19:01, Marek Polacek wrote: > When we have > > [[noreturn]] int fn1 [[nodiscard]](), fn2(); > > "noreturn" should apply to both fn1 and fn2 but "nodiscard" only to fn1: > [dcl.pre]/3: "The attribute-specifier-seq appertains to each of > the entities declared by the declarators of the init-declarator-list." > [dcl.spec.general]: "The attribute-specifier-seq affects the type > only for the declaration it appears in, not other declarations involving > the same type." > > As Ed Catmur correctly analyzed, this is because, for the test above, > we call start_decl with prefix_attributes=noreturn, but this line: > > attributes = attr_chainon (attributes, prefix_attributes); > > results in attributes == prefix_attributes, because chainon sees > that attributes is null so it just returns prefix_attributes. Then > in grokdeclarator we reach > > *attrlist = attr_chainon (*attrlist, declarator->std_attributes); > > which modifies prefix_attributes so now it's "noreturn, nodiscard" > and so fn2 is wrongly marked nodiscard as well. Fixed by copying > prefix_attributes. How about reversing the order of arguments to the call in grokdeclarator, so that the prefix attributes can remain shared at the end of the list? > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > > PR c++/106712 > > gcc/cp/ChangeLog: > > * decl.cc (start_decl): Copy prefix_attributes. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp0x/gen-attrs-77.C: New test. > --- > gcc/cp/decl.cc | 3 ++- > gcc/testsuite/g++.dg/cpp0x/gen-attrs-77.C | 17 +++++++++++++++++ > 2 files changed, 19 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp0x/gen-attrs-77.C > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index d46a347a6c7..9fa80b926d5 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -5566,7 +5566,8 @@ start_decl (const cp_declarator *declarator, > *pushed_scope_p = NULL_TREE; > > if (prefix_attributes != error_mark_node) > - attributes = attr_chainon (attributes, prefix_attributes); > + /* Don't let grokdeclarator modify prefix_attributes. */ > + attributes = attr_chainon (attributes, copy_list (prefix_attributes)); > > decl = grokdeclarator (declarator, declspecs, NORMAL, initialized, > &attributes); > diff --git a/gcc/testsuite/g++.dg/cpp0x/gen-attrs-77.C b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-77.C > new file mode 100644 > index 00000000000..2c41c62f33b > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp0x/gen-attrs-77.C > @@ -0,0 +1,17 @@ > +// PR c++/106712 > +// { dg-do compile { target c++11 } } > + > +[[noreturn]] int f1 [[nodiscard]](), f2 (); > +[[nodiscard]] int f3 (), f4 (); > +int f5 [[nodiscard]](), f6 (); > + > +int > +main () > +{ > + f1 (); // { dg-warning "ignoring" } > + f2 (); > + f3 (); // { dg-warning "ignoring" } > + f4 (); // { dg-warning "ignoring" } > + f5 (); // { dg-warning "ignoring" } > + f6 (); > +} > > base-commit: 390f94eee1ae694901f896ac45bfb148f8126baa