From patchwork Tue Aug 4 19:22:34 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1340987 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; dmarc=none (p=none dis=none) header.from=gcc.gnu.org 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=O6OsND0s; 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 4BLl5V1zTkz9sR4 for ; Wed, 5 Aug 2020 05:22:52 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 65D6D3851C0B; Tue, 4 Aug 2020 19:22:45 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 65D6D3851C0B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1596568965; bh=n7PNfo8tg1Em5DFLcZwRq5YDPjlvZNaSZJfKANCP94c=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=O6OsND0sPCUv0EMrDvrlQMJT6PeaAC4+fObM71L4mCPQpoRTEh+BtCV1QdkgpNpRl v0bv5GO+uwGBxakthLZkNwLuhrXItkUXfhZR7uK78jDFp5phcpjMLgwNolaceXWkfK /52XvQZs/MpsYrLFmQn1oQRK147noU47OGg8g1oY= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id 300043857039 for ; Tue, 4 Aug 2020 19:22:43 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 300043857039 Received: from mail-qv1-f71.google.com (mail-qv1-f71.google.com [209.85.219.71]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-161-lyGyRr6ePUqWehaj9FVarA-1; Tue, 04 Aug 2020 15:22:41 -0400 X-MC-Unique: lyGyRr6ePUqWehaj9FVarA-1 Received: by mail-qv1-f71.google.com with SMTP id r12so5218713qvx.20 for ; Tue, 04 Aug 2020 12:22:41 -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=n7PNfo8tg1Em5DFLcZwRq5YDPjlvZNaSZJfKANCP94c=; b=lZw4QHmqA5NmEDrKAGjlYWxd7veRjL5xV0y5eCCPvYg/zQOcKKmad670V9BaXGQccz QpZ1qFIYld7U+asQWu5fH1C8p2wxVTJqiKBOMbkgr+B1fHDpJ1OXq7gpUtp0pKaBoMa5 pDPhW9dfiGZZ3yZpQqLEoFw5UV4sNQeyyppXR6FA9HP0fZF7Z9gcjpIQ9VteviW+q/6r h5mJHBtImCHHMrZR74Xp6u2QCjGClV0ss5Z+V4rpySnhTHPyxI4krqzumGRw53Q1ad2f HRRmkH2V7wFQk9ENtSFb2TwIvmX/gIf1XdpdAglYj6/i9Y5XtTP8AXtK6fJntdoXL6Ah D0zA== X-Gm-Message-State: AOAM531doRvW6dD0lCH0FcOzk7aug1/V+h5dbyyznmjk6X2uGFe5cTGe 3mLm9skfEB66fSGD/EgeQlHe3SeGaTKJWsSP4dGNkZb1s8Doncx/Eh4LFI1A8W3L+gAaLwcU6Re Gu8ElADu/oqtyOZTKcA== X-Received: by 2002:aed:3203:: with SMTP id y3mr23491918qtd.376.1596568960704; Tue, 04 Aug 2020 12:22:40 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxa9mWF2ALjn9K8nyPh9UpXOvbQHDwb5TAVJ466lccvIL2PbGJwgP3rL9id9zltxnFZs4N8AA== X-Received: by 2002:aed:3203:: with SMTP id y3mr23491897qtd.376.1596568960424; Tue, 04 Aug 2020 12:22:40 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id 22sm23263878qkd.64.2020.08.04.12.22.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Aug 2020 12:22:39 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: dependent constraint on placeholder return type [PR96443] Date: Tue, 4 Aug 2020 15:22:34 -0400 Message-Id: <20200804192234.2282332-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.89.g85b4e0a6dc MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-16.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_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 below, we never substitute function-template arguments into f15's placeholder-return-type constraint, which leads to us incorrectly rejecting this instantiation in do_auto_deduction due to satisfaction failure (of the constraint SameAs). The fact that we incorrectly reject this testcase is masked by the other instantiation f15, which we correctly reject and diagnose (by accident). A good place to do this missing substitution seems to be during TEMPLATE_TYPE_PARM level lowering. So this patch adds a call to tsubst_constraint there, and also adds dg-bogus directives to this testcase wherever we expect instantiation to succeed. (So without the substitution fix, this last dg-bogus would FAIL). Successfully tested on x86_64-pc-linux-gnu, and also on the cmcstl2 and range-v3 projects. Does this look OK to commit? gcc/cp/ChangeLog: PR c++/96443 * pt.c (tsubst) : Substitute into the constraints on a placeholder type when its level. gcc/testsuite/ChangeLog: PR c++/96443 * g++.dg/cpp2a/concepts-ts1.C: Add dg-bogus wherever we expect instantiation to succeed. --- gcc/cp/pt.c | 7 ++++--- gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C | 8 ++++---- 2 files changed, 8 insertions(+), 7 deletions(-) diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index e7496002c1c..04bf6da0cdd 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -15524,10 +15524,11 @@ tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) { - /* Propagate constraints on placeholders since they are - only instantiated during satisfaction. */ + /* Substitute constraints on placeholder when reducing + their level. */ if (tree constr = PLACEHOLDER_TYPE_CONSTRAINTS (t)) - PLACEHOLDER_TYPE_CONSTRAINTS (r) = constr; + PLACEHOLDER_TYPE_CONSTRAINTS (r) + = tsubst_constraint (constr, args, complain, in_decl); else if (tree pl = CLASS_PLACEHOLDER_TEMPLATE (t)) { pl = tsubst_copy (pl, args, complain, in_decl); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C index 1cefe3b243f..1a9b71c2296 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ts1.C @@ -34,13 +34,13 @@ auto f15(auto x) -> SameAs { return 0; } // { dg-error "deduced ret void driver() { - f1(0); + f1(0); // { dg-bogus "" } f2(0); // { dg-error "" } - f3(0); + f3(0); // { dg-bogus "" } f3('a'); // { dg-error "" } - f4(0, 0); + f4(0, 0); // { dg-bogus "" } f4(0, 'a'); // { dg-error "" } - f15(0); + f15(0); // { dg-bogus "" } f15('a'); // { dg-message "" } }