From patchwork Tue Apr 13 22:36:01 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1465955 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.a=rsa-sha256 header.s=default header.b=k2xVx/xN; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [IPv6:2620:52:3:1:0:246e:9693:128c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4FKgSJ6KPcz9sV5 for ; Wed, 14 Apr 2021 08:36:15 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 92C6C3947418; Tue, 13 Apr 2021 22:36:09 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 92C6C3947418 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1618353369; bh=YPk8HAxeWLfOkxhv/L9E5msit89SMCiXB7JvdxeamTs=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=k2xVx/xNlWB1oc3mzrwqzfM2tGVXj5IznoqQd6aok3djw5BZuf4XK6pmAG529pUB3 72FxIRzWZEt4ktHrML/M9i8+fPw15mL2tL7x1McHMMBHPcK0xV1mn2au7RBncovddp eXlxNWAL5GrOstEtAqxVFvjz3mXSJXDwIAx/G0dg= 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 [216.205.24.124]) by sourceware.org (Postfix) with ESMTP id 328C93947418 for ; Tue, 13 Apr 2021 22:36:06 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 328C93947418 Received: from mail-io1-f71.google.com (mail-io1-f71.google.com [209.85.166.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-489-6f84ygPJMCemS_nXp5PY7Q-1; Tue, 13 Apr 2021 18:36:04 -0400 X-MC-Unique: 6f84ygPJMCemS_nXp5PY7Q-1 Received: by mail-io1-f71.google.com with SMTP id g12so12241746ion.15 for ; Tue, 13 Apr 2021 15:36:04 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=YPk8HAxeWLfOkxhv/L9E5msit89SMCiXB7JvdxeamTs=; b=cta1WOu3tVZgpr9Bvj0jbhIv8pneZDatMHwLrewR+AH7OeHZVNLId9s9a3Zg+YBc3A AYazFS8KYVbZBR0tA9ahHWq/TjR9VnON7hEZ1SX9jWjSOiVXYVJc81jQwJW2CUakQ/vL IOiziYABDWMn+niDpw13Qf/2HGXPzHT86DK0Q3svQIhitYjRHZ9BU4QFVs9x/QDSYFD3 gBtvgTVVUxOvEQ+BfOdbr49H20iUh2h9EIaAELI2FTjTLjTamxEQITYQh9oAv2dhYImj 9Sa0R6Z3XtxGrCTyAVgDV5HbFvLR7FZXPX0it1AwkW9vBctfRBXp1R0Atg6dHON2dJqU Ck2w== X-Gm-Message-State: AOAM533PKYsmDzicdQTdXGW67E+EwCZUvDZhjrZbajBAhKJCH1aRqUzG gQRuNbEB7fefZigcRuaKg08obmrh8LI8Uu95MZv8WuapQULUTuH5bji5pq0/58sdSP/ckNV0CVD EGG4MBWvfcmohC4ewLG+j1Gs/5tafoK0Xvjy5j9VAX53UVNqZP0mHb2pmEYqhjKXWDh8= X-Received: by 2002:a5e:d515:: with SMTP id e21mr28544692iom.30.1618353363570; Tue, 13 Apr 2021 15:36:03 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxv0JolcE0ar/TAxbfn67aUjgP/xlNd0d7aYL7EpYqEcjOLnaSN04vAr8EyptXwyGtrzOckFg== X-Received: by 2002:a5e:d515:: with SMTP id e21mr28544675iom.30.1618353363303; Tue, 13 Apr 2021 15:36:03 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id g12sm7115707ile.71.2021.04.13.15.36.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 13 Apr 2021 15:36:02 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix deduction with reference NTTP [PR83476] Date: Tue, 13 Apr 2021 18:36:01 -0400 Message-Id: <20210413223601.1413164-1-ppalka@redhat.com> X-Mailer: git-send-email 2.31.1.272.g89b43f80a5 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.2 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, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.2 X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) 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: Patrick Palka Reply-To: Patrick Palka Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In the testcase ref11.C below, during deduction for the call f(a), uses_deducible_template_parms returns false for the dependent specialization A because V is wrapped in an implicit INDIRECT_REF (formed from template_parm_to_arg), and this causes unify_one_argument to exit early, causing deduction to fail. This patch fixes this by making deducible_expression look through such implicit INDIRECT_REFs. Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? gcc/cp/ChangeLog: PR c++/83476 PR c++/99885 * pt.c (deducible_expression): Look through implicit INDIRECT_REFs as well. gcc/testsuite/ChangeLog: PR c++/83476 PR c++/99885 * g++.dg/cpp1z/class-deduction85.C: New test. * g++.dg/template/ref11.C: New test. --- gcc/cp/pt.c | 6 ++++-- gcc/testsuite/g++.dg/cpp1z/class-deduction85.C | 16 ++++++++++++++++ gcc/testsuite/g++.dg/template/ref11.C | 9 +++++++++ 3 files changed, 29 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1z/class-deduction85.C create mode 100644 gcc/testsuite/g++.dg/template/ref11.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 59df79484bf..f488a5a8c12 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -21902,8 +21902,10 @@ static bool uses_deducible_template_parms (tree type); static bool deducible_expression (tree expr) { - /* Strip implicit conversions. */ - while (CONVERT_EXPR_P (expr) || TREE_CODE (expr) == VIEW_CONVERT_EXPR) + /* Strip implicit conversions and implicit INDIRECT_REFs. */ + while (CONVERT_EXPR_P (expr) + || TREE_CODE (expr) == VIEW_CONVERT_EXPR + || REFERENCE_REF_P (expr)) expr = TREE_OPERAND (expr, 0); return (TREE_CODE (expr) == TEMPLATE_PARM_INDEX); } diff --git a/gcc/testsuite/g++.dg/cpp1z/class-deduction85.C b/gcc/testsuite/g++.dg/cpp1z/class-deduction85.C new file mode 100644 index 00000000000..0b22f8eb982 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1z/class-deduction85.C @@ -0,0 +1,16 @@ +// PR c++/99885 +// { dg-do compile { target c++17 } } + +template +struct Foo {}; + +template +struct Bar { + constexpr auto foo() const -> Foo { + return {}; + } +}; + +constexpr int a = 1; +constexpr Bar bar; +Foo foo = bar.foo(); // <-- CTAD failure diff --git a/gcc/testsuite/g++.dg/template/ref11.C b/gcc/testsuite/g++.dg/template/ref11.C new file mode 100644 index 00000000000..ef29fb72bef --- /dev/null +++ b/gcc/testsuite/g++.dg/template/ref11.C @@ -0,0 +1,9 @@ +// PR c++/83476 + +template struct A {}; +template void f(A); +int n; +int main() { + A a; + f(a); +}