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.129.124]) by sourceware.org (Postfix) with ESMTPS id 177FD384F6EB for ; Thu, 17 Nov 2022 23:57:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 177FD384F6EB 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=1668729422; 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=fFoYRtP00zX4EIqR/zsN8bjFhDaUQFZXbGg9GvmdiwQ=; b=FP1h6znDj76aF1VGupceVL5CV86iqHPdce28run4ScGntEBrPWkfpK4mPlIAUq/yA9LMzp g2SQ7MdrK/WcS3XSpPYKcuFWwm7aMURUjtbF45EwvyJnpp49UWYZCuIH06iYe6E4x+N133 d8wJc/Z9n7mI6v+0lJabCBlD9nqE6So= 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-475-UisE5Oe0PEKM2g8OhdRClA-1; Thu, 17 Nov 2022 18:57:01 -0500 X-MC-Unique: UisE5Oe0PEKM2g8OhdRClA-1 Received: by mail-qv1-f70.google.com with SMTP id lb11-20020a056214318b00b004c63b9f91e5so3074644qvb.8 for ; Thu, 17 Nov 2022 15:57:01 -0800 (PST) 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:subject:date:message-id:reply-to; bh=fFoYRtP00zX4EIqR/zsN8bjFhDaUQFZXbGg9GvmdiwQ=; b=vOEqkZ13b8Eg9d9BuejIkxd6GqsYIcm2Q2evM6Ui+WKrJLbJyP2nqeTcHcHf2RSdSn CgjhZCICiGgYp4H9Km7Tns06uqlKWJLYYBju0feet+4iym2VPDPvLJhzBud/MdPtw+TG nxl+pnqGWup1GmNVX2AOgzhEUWlUOX36c7JIZr4vvtcjfExV4bfABdzP1jTQvutXc84a meD2PLKNJIcFmt2YYJkEKEpmU8FiKUdvE+oIevQFDVVnI/c15bdGGZunNxqJWf5cdzVX 9ujsUgS4ZUKAXnOmBzTUg1iExfbXe5BXnta2nNoY++EuqpTJCkY05s+pFy3paP+ZWePh X9wQ== X-Gm-Message-State: ANoB5pn1uDEyXRQbs9MvhA3msXAqamzpfM+Mf+peRR29kI7BmatW843B +dn3lETEHwtn8nGgjgfudvznB/lPeU0MKtjUFduCeLGQzZiV2+gPUlNmvRWwSCqg7pm0dS2i3HB nTuIOCw+ijj6i6PadzA== X-Received: by 2002:ac8:734f:0:b0:3a5:a2:3486 with SMTP id q15-20020ac8734f000000b003a500a23486mr4475278qtp.560.1668729421025; Thu, 17 Nov 2022 15:57:01 -0800 (PST) X-Google-Smtp-Source: AA0mqf7sD8OrcKeMGjteT+z/EZGH8iQGLC/6nh3w0lVBNzRFe8OiUUJ3Ym2oMblVRjbScVNU09/tMA== X-Received: by 2002:ac8:734f:0:b0:3a5:a2:3486 with SMTP id q15-20020ac8734f000000b003a500a23486mr4475267qtp.560.1668729420712; Thu, 17 Nov 2022 15:57:00 -0800 (PST) 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 ey10-20020a05622a4c0a00b003a5fb681ae7sm1156426qtb.3.2022.11.17.15.56.59 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 17 Nov 2022 15:57:00 -0800 (PST) Message-ID: <395bb585-5505-b746-987a-be0a61fea027@redhat.com> Date: Thu, 17 Nov 2022 18:56:59 -0500 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.5.0 Subject: Re: [PATCH] c++: constinit on pointer to function [PR104066] To: Marek Polacek , GCC Patches References: <20221117183810.33353-1-polacek@redhat.com> From: Jason Merrill In-Reply-To: <20221117183810.33353-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.4 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,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_NONE,TXREP 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 11/17/22 13:38, Marek Polacek wrote: > [dcl.constinit]: "The constinit specifier shall be applied only to > a declaration of a variable with static or thread storage duration." > > Thus, this ought to be OK: > > constinit void (*p)() = nullptr; > > but the error message I introduced when implementing constinit was > not looking at funcdecl_p, so the code above was rejected. > > Fixed thus. I'm checking constinit_p first because I think that's > far more likely to be false than funcdecl_p. > > Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk? > I think I'd like to backport this all the way back to 10. OK for trunk and release branches. > PR c++/104066 > > gcc/cp/ChangeLog: > > * decl.cc (grokdeclarator): Check funcdecl_p before complaining > about constinit. > > gcc/testsuite/ChangeLog: > > * g++.dg/cpp2a/constinit18.C: New test. > --- > gcc/cp/decl.cc | 2 +- > gcc/testsuite/g++.dg/cpp2a/constinit18.C | 12 ++++++++++++ > 2 files changed, 13 insertions(+), 1 deletion(-) > create mode 100644 gcc/testsuite/g++.dg/cpp2a/constinit18.C > > diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc > index d28889ed865..9a7b1a6c381 100644 > --- a/gcc/cp/decl.cc > +++ b/gcc/cp/decl.cc > @@ -13071,7 +13071,7 @@ grokdeclarator (const cp_declarator *declarator, > "an array", name); > return error_mark_node; > } > - if (constinit_p) > + if (constinit_p && funcdecl_p) > { > error_at (declspecs->locations[ds_constinit], > "% on function return type is not " > diff --git a/gcc/testsuite/g++.dg/cpp2a/constinit18.C b/gcc/testsuite/g++.dg/cpp2a/constinit18.C > new file mode 100644 > index 00000000000..51b4f0273be > --- /dev/null > +++ b/gcc/testsuite/g++.dg/cpp2a/constinit18.C > @@ -0,0 +1,12 @@ > +// PR c++/104066 > +// { dg-do compile { target c++20 } } > + > +constinit void (*p)() = nullptr; > +constinit void (*pp)() = nullptr; > +void fn(); > +constinit void (&r)() = fn; > + > +extern constinit long (* const syscall_reexported) (long, ...); > + > +constinit void bad (); // { dg-error ".constinit. on function return type is not allowed" } > +constinit void bad () { } // { dg-error ".constinit. on function return type is not allowed" } > > base-commit: ee892832ea19b21a3420ef042e582204fac852a2