From patchwork Thu Jul 21 12:43:57 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Li, Pan2 via Gcc-patches" X-Patchwork-Id: 106 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:e252:0:0:0:0:0 with SMTP id bl18csp1427577wrb; Thu, 21 Jul 2022 05:44:48 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uCHiy34RabVeRlRRW6pEnsz0c0kGnzVSr9tfLFyXYe3faLWWeNeMkPGVLZ8tMnWxQ1FnQm X-Received: by 2002:a05:6402:3046:b0:43b:c9c1:864e with SMTP id bs6-20020a056402304600b0043bc9c1864emr1242195edb.32.1658407488451; Thu, 21 Jul 2022 05:44:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1658407488; cv=none; d=google.com; s=arc-20160816; b=OgnjnGIUNM+3OzKx5UoeypbveMZGkMhwWbZJzpc+P5QP7S9SUXILnPiUMSUEk1UQnM +ScZ3YJ7fiOGV9sHTdRVFFhudnt0k2diWccclMHz6RVpPSpuTAI/Z+VXs+MkX+qBThT9 KxIY9P6M4XFCa1r5hF3AeYNSqRrKXc9IqXkHS41aVBfsr1ay02T61pWcxDOAiv0fI6ry ZspV4M/1WebfjLbCf4Byf9X+p8G2qOHZPC3PQC9rujILDhvX4nOEselK3s2Jn5tfgU/k Gh9FvuYRJ5VpJnz8bFlW9WQgMFusUyxKX85rPoc5OznK/p2o/+Dv4o1w9oHvcRXW103f xJhQ== 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=a9h12uXT0KyDfZNxf0vokMP+3YRb2NnV1SY9KOrSXoA=; b=UggdouAHtsq5cxdxRbD175NxMSlSfrTFJsHH9LdHIvHKuomkOSm9vfcS0MpGOlaUHT Poa8fdMdUiwbGP2WChZw6HkmGUZUFETA4i3rY6KbhAKR/aYB/K6lOCnJx+mEkFPyc8p8 QRqaytYq4RKZeJ2RHd1D83kmJSLwSas0uni/Y6R0nikjjpQ4EUv+yBkxeOkvRvrZlENg n8cAnzbuHAFDLYLf+cgJ+RWEtCe+ZObR1XPk51E+9uriqAoLE5PAdNnkmQr2LV8tArWr a9gJ3UK8Lir5otaJ8ZqY4kiHZSdDGmfHOdgJloaqzQ83Rl5L46QAP80LeaZD5xC4YoU6 Tbpw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UnkxQt53; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 (server2.sourceware.org. [2620:52:3:1:0:246e:9693:128c]) by mx.google.com with ESMTPS id z5-20020a1709063a0500b0072b8fe2ca6asi1832768eje.962.2022.07.21.05.44.48 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 05:44:48 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c as permitted sender) client-ip=2620:52:3:1:0:246e:9693:128c; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UnkxQt53; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 2620:52:3:1:0:246e:9693:128c 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 39C08385702D for ; Thu, 21 Jul 2022 12:44:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 39C08385702D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1658407487; bh=a9h12uXT0KyDfZNxf0vokMP+3YRb2NnV1SY9KOrSXoA=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=UnkxQt53WVFk7yjgaQoJjKhbe/MryzPQi1MV99FDakANAekRReAp6gQXg1T43+bDl g2uju59ZQvJIgXxGwjoXP1oigyMX7/0L6pMiSrFYpGq6iGMnPxQL+atvhzstDbqd1r V8U0NAM1TbGtSq78bVFYoMh1IcHBLOSGuQS+5+Z4= 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 7A45A38582A1 for ; Thu, 21 Jul 2022 12:44:03 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 7A45A38582A1 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.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-193-Zmf3RGo9OTa2ra9YW6Cvcw-1; Thu, 21 Jul 2022 08:44:00 -0400 X-MC-Unique: Zmf3RGo9OTa2ra9YW6Cvcw-1 Received: by mail-qv1-f70.google.com with SMTP id d18-20020a0cfe92000000b0047342562073so980184qvs.1 for ; Thu, 21 Jul 2022 05:44:00 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=a9h12uXT0KyDfZNxf0vokMP+3YRb2NnV1SY9KOrSXoA=; b=GTI9lvzvZ4kgjM6wMATxEK9i20W0JqYHcyu25c7PA6dWF0YAwK3abTEZjkKuyRT4sR bP7rtki0tP8tsBt5rW7UZlEQsTXhx7SZjM6o9EdWpAsQ47JdEiusLjToCbVYrmaVGxgE iGzZ3IxKO/ejqpJrL8WC8VpoTV5/xHJmKe1zCKOEDxSrIG+qCTR3LLFg7yeyfA7+SLrc gsgklVqmWL2inyQs82iQJzup5kY6RNfXjoEOC//ghgbtxqSrDXOnYlzs9LwfPjGRE9AL e9pRYzhjJSsuJqFJsrqyiCMHG+/ZDGWugMSd4X88dbFG89hbOKRNOB2qK+DmCDaUfhPw vTiQ== X-Gm-Message-State: AJIora/JkW5AZcyajg+vLROgnYVYRuuKMvKaDf8+606fDeZBzi/8pAlt wBPbrRjwFxJRtMwudg2ZToPNqS1nb9vi5DTSZNoh7/TgN4hm3EmeNNxbMnBf853rLVVq4zy+iIz 0M45rt44F/JldF7OyidZaVsKEjgPCHlJ2YbfhSP2VVZKxfrfq4y1zxZDWNT9lrGYA0+8= X-Received: by 2002:a05:622a:1210:b0:31e:e139:a6d4 with SMTP id y16-20020a05622a121000b0031ee139a6d4mr21526246qtx.160.1658407439977; Thu, 21 Jul 2022 05:43:59 -0700 (PDT) X-Received: by 2002:a05:622a:1210:b0:31e:e139:a6d4 with SMTP id y16-20020a05622a121000b0031ee139a6d4mr21526226qtx.160.1658407439625; Thu, 21 Jul 2022 05:43:59 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id u13-20020a05620a0c4d00b0069fe1dfbeffsm1343569qki.92.2022.07.21.05.43.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 21 Jul 2022 05:43:59 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: CTAD from initializer list [PR106366] Date: Thu, 21 Jul 2022 08:43:57 -0400 Message-Id: <20220721124357.284497-1-ppalka@redhat.com> X-Mailer: git-send-email 2.37.1.208.ge72d93e88c MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-14.6 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_LOW, 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: Patrick Palka via Gcc-patches From: "Li, Pan2 via Gcc-patches" Reply-To: Patrick Palka 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?1738966290427333727?= X-GMAIL-MSGID: =?utf-8?q?1738966290427333727?= During CTAD, we currently perform the first phase of overload resolution from [over.match.list] only if the class template has a list constructor. But according to [over.match.class.deduct]/4 it should be enough to just have a guide that looks like a list constructor (which is a more general criterion in light of user-defined guides). Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? PR c++/106366 gcc/cp/ChangeLog: * pt.cc (do_class_deduction): Don't consider TYPE_HAS_LIST_CTOR when setting try_list_ctor. Reset args even when try_list_ctor is true and there are no list candidates. Call resolve_args on the reset args. gcc/testsuite/ChangeLog: * g++.dg/cpp1z/class-deduction112.C: New test. --- gcc/cp/pt.cc | 25 +++++++++---------- .../g++.dg/cpp1z/class-deduction112.C | 14 +++++++++++ 2 files changed, 26 insertions(+), 13 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction112.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 718dfa5bfa8..0f26d6f5bce 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -30250,8 +30250,8 @@ do_class_deduction (tree ptype, tree tmpl, tree init, else if (BRACE_ENCLOSED_INITIALIZER_P (init)) { list_init_p = true; - try_list_ctor = TYPE_HAS_LIST_CTOR (type); - if (try_list_ctor && CONSTRUCTOR_NELTS (init) == 1 + try_list_ctor = true; + if (CONSTRUCTOR_NELTS (init) == 1 && !CONSTRUCTOR_IS_DESIGNATED_INIT (init)) { /* As an exception, the first phase in 16.3.1.7 (considering the @@ -30310,26 +30310,25 @@ do_class_deduction (tree ptype, tree tmpl, tree init, tree fndecl = error_mark_node; - /* If this is list-initialization and the class has a list constructor, first + /* If this is list-initialization and the class has a list guide, first try deducing from the list as a single argument, as [over.match.list]. */ - tree list_cands = NULL_TREE; - if (try_list_ctor && cands) - for (lkp_iterator iter (cands); iter; ++iter) - { - tree dg = *iter; + if (try_list_ctor) + { + tree list_cands = NULL_TREE; + for (tree dg : lkp_range (cands)) if (is_list_ctor (dg)) list_cands = lookup_add (dg, list_cands); - } - if (list_cands) - { - fndecl = perform_dguide_overload_resolution (list_cands, args, tf_none); - + if (list_cands) + fndecl = perform_dguide_overload_resolution (list_cands, args, tf_none); if (fndecl == error_mark_node) { /* That didn't work, now try treating the list as a sequence of arguments. */ release_tree_vector (args); args = make_tree_vector_from_ctor (init); + args = resolve_args (args, complain); + if (args == NULL) + return error_mark_node; } } diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction112.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction112.C new file mode 100644 index 00000000000..8da5868ff98 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction112.C @@ -0,0 +1,14 @@ +// PR c++/106366 +// { dg-do compile { target c++17 } } + +#include + +template +struct A { A(...); }; + +template +A(std::initializer_list) -> A; + +A a{1,2,3}; +using type = decltype(a); +using type = A;