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 8D6993858D39 for ; Wed, 19 Oct 2022 08:00:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 8D6993858D39 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=1666166443; h=from:from:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type; bh=BpwJKrWpnKrYMxHYF8FyGD7NArEv8neuuisvRot5I3g=; b=SgccNOyb11+GT58EDUl1SaD+xRBl7UtGC7V8ZPkKh8lLh+Uf1HTZI9owCTqpO35bDvQHw2 sgPL0fF9Y61HRnj6jlnXmAAOTYZ1eXJHOW8ID121yBi/O3i2/EBqYdEMV4DaQ8GQsY2xIw SF1di1z2zpUkXmf2fNLtDawaAp6b3Js= Received: from mimecast-mx02.redhat.com (mimecast-mx02.redhat.com [66.187.233.88]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-581-SJrKeZaZNdqdhMhySJbnIQ-1; Wed, 19 Oct 2022 04:00:41 -0400 X-MC-Unique: SJrKeZaZNdqdhMhySJbnIQ-1 Received: from smtp.corp.redhat.com (int-mx08.intmail.prod.int.rdu2.redhat.com [10.11.54.8]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 20A63823F74 for ; Wed, 19 Oct 2022 08:00:41 +0000 (UTC) Received: from tucnak.zalov.cz (unknown [10.39.193.252]) by smtp.corp.redhat.com (Postfix) with ESMTPS id CCCCAC1908B; Wed, 19 Oct 2022 08:00:40 +0000 (UTC) Received: from tucnak.zalov.cz (localhost [127.0.0.1]) by tucnak.zalov.cz (8.17.1/8.17.1) with ESMTPS id 29J80cNE3797121 (version=TLSv1.3 cipher=TLS_AES_256_GCM_SHA384 bits=256 verify=NOT); Wed, 19 Oct 2022 10:00:38 +0200 Received: (from jakub@localhost) by tucnak.zalov.cz (8.17.1/8.17.1/Submit) id 29J80bwW3797120; Wed, 19 Oct 2022 10:00:37 +0200 Date: Wed, 19 Oct 2022 10:00:37 +0200 From: Jakub Jelinek To: Jason Merrill Cc: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix up mangling ICE with void{} [PR106863] Message-ID: Reply-To: Jakub Jelinek MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.8 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com Content-Type: text/plain; charset=us-ascii Content-Disposition: inline X-Spam-Status: No, score=-3.8 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,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: Hi! We ICE on the following testcase during mangling, finish_compound_literal returns for void{} void_node and the mangler doesn't handle it. Handling void_node in the mangler seems problematic to me, because we don't know for which case it has been created. The following patch arranges to mangle just void{} the same as void() if that is what we want to use, by doing what we do for void() when processing void{}. The code does that only if processing_template_decl, because otherwise build_functional_cast will return void_node, so calling it looks like wasted effort to me. But if you want to call it unconditionally, I can certainly do that too. Or do you want to mangle it differently? How? clang++ doesn't support DR2351, so I can't check what they are doing. Bootstrapped/regtested on x86_64-linux and i686-linux. 2022-10-19 Jakub Jelinek PR c++/106863 * semantics.cc (finish_compound_literal): For void{}, if processing_template_decl return build_functional_cast of NULL_TREE to VOID_TYPE rather than void_node. * g++.dg/cpp0x/dr2351-2.C: New test. --- gcc/cp/semantics.cc.jj 2022-10-10 09:31:57.410985121 +0200 +++ gcc/cp/semantics.cc 2022-10-18 15:24:08.726026118 +0200 @@ -3164,7 +3164,12 @@ finish_compound_literal (tree type, tree { /* DR2351 */ if (VOID_TYPE_P (type) && CONSTRUCTOR_NELTS (compound_literal) == 0) - return void_node; + { + if (!processing_template_decl) + return void_node; + location_t loc = cp_expr_loc_or_input_loc (compound_literal); + return build_functional_cast (loc, type, NULL_TREE, complain); + } else if (VOID_TYPE_P (type) && processing_template_decl && maybe_zero_constructor_nelts (compound_literal)) --- gcc/testsuite/g++.dg/cpp0x/dr2351-2.C.jj 2022-10-18 15:27:01.146690132 +0200 +++ gcc/testsuite/g++.dg/cpp0x/dr2351-2.C 2022-10-18 15:27:39.909164970 +0200 @@ -0,0 +1,16 @@ +// DR2351 +// { dg-do compile { target c++11 } } + +void bar (int); + +template +auto foo (T t) -> decltype (bar (t), void{}) +{ + return bar (t); +} + +int +main () +{ + foo (0); +} Jakub