From patchwork Mon Feb 13 17:06:19 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Marek Polacek X-Patchwork-Id: 56397 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2460135wrn; Mon, 13 Feb 2023 09:07:17 -0800 (PST) X-Google-Smtp-Source: AK7set8ZY7N3LRPhEP0pWfrCwa622bSu+S9csGXWX2gaOH+atHF8xhLVGxBW4lAF6nz8F+NlVlNC X-Received: by 2002:a17:906:a859:b0:878:43b9:6b8d with SMTP id dx25-20020a170906a85900b0087843b96b8dmr17061865ejb.25.1676308037490; Mon, 13 Feb 2023 09:07:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676308037; cv=none; d=google.com; s=arc-20160816; b=TMs7pzTlOG7qSUHBFWB9vTjgva2H8eRxitgicnk2PDqMZ0fxgYjtM7442hxkGu4wOq 1gIGbxoabSiUT5QXEX2mWxwItsP3MriB5lLRvH1Vfpn33vEAQIVFiUw65o3WdqRE1d+u 9TYdrcNGNU6ErLkihkrKAYWmvHqw3pvI2luT4OzJ49UbDldx65l4yC7lbdDxA8gRPDPO fiWnelvBPHEP3wsTnIZRTAc4c6PkWeqVJOUbvHFhRTkTU+hqaslIMtW8t5Zma3p2QnN9 dL9zQhpSfxgZC5QcITeURISaAR+Ol57UfiXKrqUcXYJfNGGTbZgvAhrUxNhRb5QRwMYi jETw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:to :dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=d7HaYsIsrVR0kT8+mtP7ShLbt6UPM63H3DH9w2TrWxg=; b=h/DTAM9AVZo/cGYvaNjAg3QEr8qxRG76ELV0/bAS4VEsu3FmL6eRGhZjrRV1qh7wyl BKVMlV21AqY0yeYmprOL5XjdRxNX63CO7stNyWroNhlSTnCpxfbLn7/1YoQ/JT77tQNP UMJ/hhwerWq7v4Gly6qKvoUgTvh/y7xstMa+vsCEWceRFmZ+c28SHYx/epMpvOW2PaYw mXKbNh59rw7JK5/8eqcQX4JP/xNUX92j1p+3EHUGp30c1YlArkzLKaLyovAm3zBcb12a CEZpuvu8FsP5tVayYM9fRSMVrrkqmcM4d5ORvE9lYXxyirrH9w2mzgi0wSDv5dJlrL45 n8Ug== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UfN9q2o0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (ip-8-43-85-97.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id ay21-20020a170907901500b007abafd4d7d0si5576373ejc.702.2023.02.13.09.07.17 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 13 Feb 2023 09:07:17 -0800 (PST) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UfN9q2o0; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 473C7385840A for ; Mon, 13 Feb 2023 17:07:16 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 473C7385840A DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1676308036; bh=d7HaYsIsrVR0kT8+mtP7ShLbt6UPM63H3DH9w2TrWxg=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UfN9q2o0DO2t3a7KgAWIOIxy9tbtfd49y1DSzn++EhAij8xXQCY4U4Jkoxkv/U5Cv /xdhC1U9EOWaYBcE7tx0bjiHodR7PkmJs9Ai5pjoa09rsLhBFOvYsySkC0P1xFXWmb lRE6E3jQDsrwKVOlasZAwyyEQ3Q2aMVzblhH/fi8= 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.133.124]) by sourceware.org (Postfix) with ESMTPS id BF9D33858288 for ; Mon, 13 Feb 2023 17:06:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org BF9D33858288 Received: from mimecast-mx02.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-650-EPDUgEf5OIOHGP0x7iBDbw-1; Mon, 13 Feb 2023 12:06:29 -0500 X-MC-Unique: EPDUgEf5OIOHGP0x7iBDbw-1 Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mimecast-mx02.redhat.com (Postfix) with ESMTPS id 215D33C14101 for ; Mon, 13 Feb 2023 17:06:28 +0000 (UTC) Received: from pdp-11.lan (unknown [10.22.17.209]) by smtp.corp.redhat.com (Postfix) with ESMTP id 01A2F2026D4B; Mon, 13 Feb 2023 17:06:27 +0000 (UTC) To: Jason Merrill , GCC Patches Subject: [PATCH] c++: fix ICE in joust_maybe_elide_copy [PR106675] Date: Mon, 13 Feb 2023 12:06:19 -0500 Message-Id: <20230213170619.28996-1-polacek@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 3.1 on 10.11.54.4 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, 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 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: Marek Polacek via Gcc-patches From: Marek Polacek Reply-To: Marek Polacek Errors-To: gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1757736376360158853?= X-GMAIL-MSGID: =?utf-8?q?1757736376360158853?= joust_maybe_elide_copy checks that the last conversion in the ICS for the first argument is ck_ref_bind, which is reasonable, because we've checked that we're dealing with a copy/move constructor. But it can also happen that we couldn't figure out which conversion function is better to convert the argument, as in this testcase: joust couldn't decide if we should go with operator foo &() or operator foo const &() so we get a ck_ambig, which then upsets joust_maybe_elide_copy. Since a ck_ambig can validly occur, I think we should just return early, as in the patch below. Bootstrapped/regtested on x86_64-pc-linux-gnu, ok for trunk/12? PR c++/106675 gcc/cp/ChangeLog: * call.cc (joust_maybe_elide_copy): Return false for ck_ambig. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/overload-conv-5.C: New test. --- gcc/cp/call.cc | 2 ++ gcc/testsuite/g++.dg/cpp0x/overload-conv-5.C | 21 ++++++++++++++++++++ 2 files changed, 23 insertions(+) create mode 100644 gcc/testsuite/g++.dg/cpp0x/overload-conv-5.C base-commit: 72ae1e5635648bd3f6a5760ca46d531ad1f2c6b1 diff --git a/gcc/cp/call.cc b/gcc/cp/call.cc index a349d8e79db..048b2b052f8 100644 --- a/gcc/cp/call.cc +++ b/gcc/cp/call.cc @@ -12542,6 +12542,8 @@ joust_maybe_elide_copy (z_candidate *&cand) if (!DECL_COPY_CONSTRUCTOR_P (fn) && !DECL_MOVE_CONSTRUCTOR_P (fn)) return false; conversion *conv = cand->convs[0]; + if (conv->kind == ck_ambig) + return false; gcc_checking_assert (conv->kind == ck_ref_bind); conv = next_conversion (conv); if (conv->kind == ck_user && !TYPE_REF_P (conv->type)) diff --git a/gcc/testsuite/g++.dg/cpp0x/overload-conv-5.C b/gcc/testsuite/g++.dg/cpp0x/overload-conv-5.C new file mode 100644 index 00000000000..b1e7766e42b --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp0x/overload-conv-5.C @@ -0,0 +1,21 @@ +// PR c++/106675 +// { dg-do compile { target c++11 } } + +struct foo { + int n_; + foo(int n) : n_(n) {} +}; + +struct bar { + int n_; + + operator foo() const { + return foo(n_); + } + operator foo &() { return *reinterpret_cast(n_); } + operator foo const &() = delete; + + void crashgcc() { + foo tmp(*this); // { dg-error "ambiguous" } + } +};