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 A19AB3857C4E for ; Thu, 28 Oct 2021 12:01:32 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org A19AB3857C4E Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-45-bZ-Pm1EYNv2VDgIZpXmaVw-1; Thu, 28 Oct 2021 08:01:31 -0400 X-MC-Unique: bZ-Pm1EYNv2VDgIZpXmaVw-1 Received: by mail-qk1-f198.google.com with SMTP id h2-20020a05620a10a200b00462c87635cdso1773731qkk.15 for ; Thu, 28 Oct 2021 05:01:31 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:date:mime-version:user-agent:subject :content-language:to:cc:references:from:in-reply-to :content-transfer-encoding; bh=CzINs3Op1s5zGeaDc/OakAGOrTAMKG1KK8GMSTUeTtU=; b=DMOk8X/7vfYY5r5Kh8TRi53KxxDpK4fgEKLN95b6rUl6p0RJdzhgoU5D0TQ5RVOYAd 8+D0fUsIHYh3lzxcAABGUTTRcNuHA4KRhQk0kODGO0aXEIbNaKu1eWSsM4QlW7fa4HA+ Kz6ty5XQRHwiFVKwwdCuf46L8VsnZ2AhpiHKLAXpD6ZSwBs1ZFhipQs+1DnFpmT4MV3W a4V1ji3CuiTyiEsTs60PRIhgCp+uKibZVnTm5wc5iAe/tyr5imLKHIxMHb8CN1sMoFgE AXrKKlHiPyGnSq+5gbIspMcEjSWLdFndVmIzgewSdhuoBO8slO5LGK7b2tnAgzz6Rh5D NHaQ== X-Gm-Message-State: AOAM531bWAOprnNu0YRCu4xyX1ORcSjOCcQq1yWa3Edaf0eZE9ssUY5y o/UV/6xAr4nH8w2eHzs+DiDJUQEn3A8C5oUlJOnKVlT5Aypqmr7Gi/Ea+zpNvK8dI8Y//34lwmZ u/EbPWII9Rqd/tAUyUw== X-Received: by 2002:a05:620a:4554:: with SMTP id u20mr3015568qkp.458.1635422489895; Thu, 28 Oct 2021 05:01:29 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx4RYy3tXWD5C/b4NiDCpW6sEobt8BYxiHb02wD3mogE4KzEp9dj2zcx92u3BQNBjxWIjnMTg== X-Received: by 2002:a05:620a:4554:: with SMTP id u20mr3015520qkp.458.1635422489459; Thu, 28 Oct 2021 05:01:29 -0700 (PDT) Received: from [192.168.1.149] (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 s15sm2056420qkp.98.2021.10.28.05.01.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 28 Oct 2021 05:01:28 -0700 (PDT) Message-ID: Date: Thu, 28 Oct 2021 08:01:27 -0400 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:91.0) Gecko/20100101 Thunderbird/91.2.1 Subject: Re: [PATCH] c++, v2: Implement DR2351 - void{} [PR102820] To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org References: <20211021084240.GE304296@tucnak> <20211028112634.GO304296@tucnak> From: Jason Merrill In-Reply-To: <20211028112634.GO304296@tucnak> 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=-8.2 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, NICE_REPLY_A, RCVD_IN_DNSWL_LOW, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) 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-List-Received-Date: Thu, 28 Oct 2021 12:01:34 -0000 On 10/28/21 07:26, Jakub Jelinek wrote: > On Wed, Oct 27, 2021 at 04:58:53PM -0400, Jason Merrill wrote: >> On 10/21/21 04:42, Jakub Jelinek wrote: >>> Hi! >>> >>> Here is an attempt to implement DR2351 - void{} - where void{} after >>> pack expansion is considered valid and the same thing as void(). >>> For templates, dunno if we have some better way to check if a CONSTRUCTOR >>> might be empty after pack expansion. Would that only if the constructor >>> only contains EXPR_PACK_EXPANSION elements and nothing else, or something >>> else too? >> >> I think that's the only case. For template args there's the >> pack_expansion_args_count function, but I don't think there's anything >> similar for constructor elts; please feel free to add it. > > Ok. But counting how many packs its CONSTRUCTOR_ELTS have and then comparing > that number against CONSTRUCTOR_NELTS seems to be unnecessarily expensive if > there are many elements, for the purpose the DR2351 code needs we can stop > as soon as we see first non-pack element. > > So what about this if it passes bootstrap/regtest? > > 2021-10-28 Jakub Jelinek > > PR c++/102820 > * semantics.c (maybe_zero_constructor_nelts): New function. > (finish_compound_literal): Implement DR2351 - void{}. > If type is cv void and compound_literal has no elements, return > void_node. If type is cv void and compound_literal might have no > elements after expansion, handle it like other dependent compound > literals. > > * g++.dg/cpp0x/dr2351.C: New test. > > --- gcc/cp/semantics.c.jj 2021-10-27 09:16:41.161600606 +0200 > +++ gcc/cp/semantics.c 2021-10-28 13:06:59.325791588 +0200 > @@ -3079,6 +3079,24 @@ finish_unary_op_expr (location_t op_loc, > return result; > } > > +/* Return true if CONSTRUCTOR EXPR after pack expansion could have no > + elements. */ > + > +static bool > +maybe_zero_constructor_nelts (tree expr) > +{ > + if (CONSTRUCTOR_NELTS (expr) == 0) > + return true; > + if (!processing_template_decl) > + return false; > + unsigned int i; > + tree val; > + FOR_EACH_CONSTRUCTOR_VALUE (CONSTRUCTOR_ELTS (expr), i, val) Let's use for (constructor_elt &elt : CONSTRUCTOR_ELTS (t)) > + if (!PACK_EXPANSION_P (val)) > + return false; > + return true; > +} > + > /* Finish a compound-literal expression or C++11 functional cast with aggregate > initializer. TYPE is the type to which the CONSTRUCTOR in COMPOUND_LITERAL > is being cast. */ > @@ -3104,9 +3122,20 @@ finish_compound_literal (tree type, tree > > if (!TYPE_OBJ_P (type)) > { > - if (complain & tf_error) > - error ("compound literal of non-object type %qT", type); > - return error_mark_node; > + /* DR2351 */ > + if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0) > + return void_node; This test now seems redundant with the one below (if you remove the && processing_template_decl). OK with those tweaks. > + else if (VOID_TYPE_P (type) > + && processing_template_decl > + && maybe_zero_constructor_nelts (compound_literal)) > + /* If there are only packs in compound_literal, it could > + be void{} after pack expansion. */; > + else > + { > + if (complain & tf_error) > + error ("compound literal of non-object type %qT", type); > + return error_mark_node; > + } > } > > if (template_placeholder_p (type)) > --- gcc/testsuite/g++.dg/cpp0x/dr2351.C.jj 2021-10-28 12:59:27.987120315 +0200 > +++ gcc/testsuite/g++.dg/cpp0x/dr2351.C 2021-10-28 13:15:20.532760871 +0200 > @@ -0,0 +1,51 @@ > +// DR2351 > +// { dg-do compile { target c++11 } } > + > +void > +foo () > +{ > + void{}; > + void(); > +} > + > +template > +void > +bar (T... t) > +{ > + void{t...}; > + void(t...); > +} > + > +void > +baz () > +{ > + bar (); > +} > + > +template > +void > +qux (T... t) > +{ > + void{t...}; // { dg-error "compound literal of non-object type" } > +} > + > +void > +corge () > +{ > + qux (1, 2); > +} > + > +template > +void > +garply (T... t) > +{ > + void{t..., t..., t...}; > + void(t..., t..., t...); > +} > + > +template > +void > +grault (T... t) > +{ > + void{t..., 1}; // { dg-error "compound literal of non-object type" } > +} > > > Jakub >