From patchwork Thu Oct 21 08:42:40 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jakub Jelinek X-Patchwork-Id: 46478 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id A42823857C4C for ; Thu, 21 Oct 2021 08:43:15 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org A42823857C4C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1634805795; bh=Y2ycLeibhwa5WepBlpOimypl9FVtOZEtDDjS6sCUX0k=; h=Date:To:Subject:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=RDrM4bhInS7pPXskcaaxy2N9BpdFIS63DKsZn4d9vJjmy0uZl8voJBu9cIAu8N/SG GhcHVDaSNDjOfUL503h2S4UmmVXLtLZNWD5LVrxw0JjV0SMKIP85bVzpcHD3CQ0dl4 Tg/2/Hu3wyH/GSbNHh98wcIDSynD+fRal5O8w3Vk= 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 [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id B99953858416 for ; Thu, 21 Oct 2021 08:42:46 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org B99953858416 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-143-AX99ztKuN3yGs1vZagsd6g-1; Thu, 21 Oct 2021 04:42:44 -0400 X-MC-Unique: AX99ztKuN3yGs1vZagsd6g-1 Received: from smtp.corp.redhat.com (int-mx07.intmail.prod.int.phx2.redhat.com [10.5.11.22]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx01.redhat.com (Postfix) with ESMTPS id 02D701006AA2 for ; Thu, 21 Oct 2021 08:42:44 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.172]) by smtp.corp.redhat.com (Postfix) with ESMTPS id 90074100164A; Thu, 21 Oct 2021 08:42:43 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.16.1/8.16.1) with ESMTPS id 19L8gfW53873535 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Thu, 21 Oct 2021 10:42:41 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.16.1/8.16.1/Submit) id 19L8geG53873534; Thu, 21 Oct 2021 10:42:40 +0200 Date: Thu, 21 Oct 2021 10:42:40 +0200 To: Jason Merrill Subject: [PATCH] c++: Implement DR2351 - void{} [PR102820] Message-ID: <20211021084240.GE304296@tucnak> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.84 on 10.5.11.22 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Disposition: inline X-Spam-Status: No, score=-5.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, 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-Patchwork-Original-From: Jakub Jelinek via Gcc-patches From: Jakub Jelinek Reply-To: Jakub Jelinek Cc: gcc-patches@gcc.gnu.org Errors-To: gcc-patches-bounces+patchwork=sourceware.org@gcc.gnu.org Sender: "Gcc-patches" 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? With the patch as is we wouldn't diagnose template void bar (T... t) { void{1, t...}; } at parsing time, only at instantiation time, even when it will always expand to at least one CONSTRUCTOR elt. Bootstrapped/regtested on x86_64-linux and i686-linux. 2021-10-21 Jakub Jelinek PR c++/102820 * semantics.c (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 is instantiation dependent, handle it like other dependent compound literals. * g++.dg/cpp0x/dr2351.C: New test. Jakub --- gcc/cp/semantics.c.jj 2021-10-15 11:58:45.079131947 +0200 +++ gcc/cp/semantics.c 2021-10-20 17:00:38.586705600 +0200 @@ -3104,9 +3104,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; + else if (VOID_TYPE_P (type) + && processing_template_decl + && instantiation_dependent_expression_p (compound_literal)) + /* If there are 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-20 17:06:02.399162937 +0200 +++ gcc/testsuite/g++.dg/cpp0x/dr2351.C 2021-10-20 17:05:54.294276511 +0200 @@ -0,0 +1,36 @@ +// 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); +}