From patchwork Tue Jun 2 19:43:46 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1302596 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=YvDtCW6K; 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 49c2Xz6Khkz9sSF for ; Wed, 3 Jun 2020 05:44:01 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 43BEC3870851; Tue, 2 Jun 2020 19:43:54 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 43BEC3870851 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1591127034; bh=NNJIrjNk0hKvwnWWgn9MRYPGZbQ0tYFtxRotCYR131w=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=YvDtCW6KUUexZ81yOzi8Y4vWbTRg3w2k3gH/vyiISilwB29bYIIS2q9NEzsbsMxGf gplTb/yvUpXgPIydN0ae2p4azSglLt4ktBlwRF/3fyuzMPRHgSFGny2w1uXNp/2a0W qugNwZ0hMaqotnlwxQKPe7kzi/h3AojT7Pedy8v8= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-1.mimecast.com (us-smtp-delivery-1.mimecast.com [207.211.31.120]) by sourceware.org (Postfix) with ESMTP id F41CC3851C24 for ; Tue, 2 Jun 2020 19:43:51 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F41CC3851C24 Received: from mail-qv1-f72.google.com (mail-qv1-f72.google.com [209.85.219.72]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-91-_8sR3JuBMkene2NFDYzWug-1; Tue, 02 Jun 2020 15:43:50 -0400 X-MC-Unique: _8sR3JuBMkene2NFDYzWug-1 Received: by mail-qv1-f72.google.com with SMTP id da20so4576873qvb.3 for ; Tue, 02 Jun 2020 12:43:50 -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=NNJIrjNk0hKvwnWWgn9MRYPGZbQ0tYFtxRotCYR131w=; b=EQCw7tSbuNp/MGnTzHbkLrXcIXTn+d08AhvAFTohpzl9vjjW0w3wGp7A50EFKb3TPK k4W8aoqiV/KUEMGdE54lBIIIWQFhxGIXVUQRmqESSs1Os5DzdrKrG4JfTPXdLWJ87mPf BWL+llcoOYwPXakzeJFbjYkloeQXLuwRvQDoF67wWdJo5Z87xrKyLzgmYCUdsQFCXOUf Q5ApKfsVHscEGD//IflROgKqYdZgW4XerAiFdie2wdPJ6XHPnrTcy0wlxuJ3+hhoxsgO Low+0m3o5LbwY2LXC+6FyH4GAm0kTEyPX6rxDtzWYZ2BIHDW+yfAAsDkmrwlMwxi8lsw Gsmg== X-Gm-Message-State: AOAM532eEdLXqkhD/tVFkQkBpOMov1MLaYUgILUZs8eCPuBkOYIhCkdy gWECOvtnpUOS1R6Dm4Tc6VjFeG1mnP3E1O7dZoHsXpZ5JZnl7FcBzpsJiHObjbaGSlhd2gb3eUb MmVmHrkWA5Xv0v8H2ow== X-Received: by 2002:a0c:b259:: with SMTP id k25mr26648789qve.111.1591127029372; Tue, 02 Jun 2020 12:43:49 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyIg/rVViDH3Di5iM2JLYR3KkV8drCnL/wrGuqrw/qhXCAexsin4PHeY5/pOmzK0Qfo1ETasA== X-Received: by 2002:a0c:b259:: with SMTP id k25mr26648758qve.111.1591127028908; Tue, 02 Jun 2020 12:43:48 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id u27sm3086112qku.13.2020.06.02.12.43.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 02 Jun 2020 12:43:48 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: constrained nested partial specialization [PR92103] Date: Tue, 2 Jun 2020 15:43:46 -0400 Message-Id: <20200602194346.701957-1-ppalka@redhat.com> X-Mailer: git-send-email 2.27.0.rc1.5.gae92ac8ae3 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-18.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_H3, 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" When determining the most specialized partial specialization of a primary template that is nested inside a class template, we first tsubst the outer template arguments into the TEMPLATE_DECL of each partial specialization, and then check for satisfaction of the new TEMPLATE_DECL's constraints. But tsubst_template_decl does not currently guarantee that constraints from the original DECL_TEMPLATE_RESULT get reattached to the new DECL_TEMPLATE_RESULT. In the testcase below, this leads to the constraints_satisfied_p check in most_specialized_partial_spec to trivially return true for each of the partial specializations. I'm not sure if such a guarantee would be desirable, but in any case we can just check constraints_satisfied_p on the original TEMPLATE_DECL instead of on the tsubsted TEMPLATE_DECL here, which is what this patch does (alongside some reorganizing). Passes 'make check-c++' and also tested by building the testsuites of cmcstl2 and range-v3. Does this look OK to commit to mainline and to the 10 branch after a full bootstrap and regtest? gcc/cp/ChangeLog: PR c++/92103 * pt.c (most_specialized_partial_spec): Reorganize the loop over DECL_TEMPLATE_SPECIALIZATIONS. Check constraints_satisfied_p on the original template declaration, not on the substituted one. gcc/testsuite/ChangeLog: PR c++/92103 * g++.dg/cpp2a/concepts-partial-spec7.C: New test. --- gcc/cp/pt.c | 19 ++++++++-------- .../g++.dg/cpp2a/concepts-partial-spec7.C | 22 +++++++++++++++++++ 2 files changed, 32 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec7.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 907ca879c73..df92f5584cf 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -24482,21 +24482,22 @@ most_specialized_partial_spec (tree target, tsubst_flags_t complain) for (t = DECL_TEMPLATE_SPECIALIZATIONS (main_tmpl); t; t = TREE_CHAIN (t)) { - tree spec_args; - tree spec_tmpl = TREE_VALUE (t); + const tree ospec_tmpl = TREE_VALUE (t); + tree spec_tmpl; if (outer_args) { /* Substitute in the template args from the enclosing class. */ ++processing_template_decl; - spec_tmpl = tsubst (spec_tmpl, outer_args, tf_none, NULL_TREE); + spec_tmpl = tsubst (ospec_tmpl, outer_args, tf_none, NULL_TREE); --processing_template_decl; + if (spec_tmpl == error_mark_node) + return error_mark_node; } + else + spec_tmpl = ospec_tmpl; - if (spec_tmpl == error_mark_node) - return error_mark_node; - - spec_args = get_partial_spec_bindings (tmpl, spec_tmpl, args); + tree spec_args = get_partial_spec_bindings (tmpl, spec_tmpl, args); if (spec_args) { if (outer_args) @@ -24505,9 +24506,9 @@ most_specialized_partial_spec (tree target, tsubst_flags_t complain) /* Keep the candidate only if the constraints are satisfied, or if we're not compiling with concepts. */ if (!flag_concepts - || constraints_satisfied_p (spec_tmpl, spec_args)) + || constraints_satisfied_p (ospec_tmpl, spec_args)) { - list = tree_cons (spec_args, TREE_VALUE (t), list); + list = tree_cons (spec_args, ospec_tmpl, list); TREE_TYPE (list) = TREE_TYPE (t); } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec7.C b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec7.C new file mode 100644 index 00000000000..5b3afce3bc7 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-partial-spec7.C @@ -0,0 +1,22 @@ +// PR c++/92103 +// { dg-do compile { target c++20 } } + +template +struct traits +{ + template + struct equal_to + { static constexpr bool value = false; }; + + template requires (M == N) + struct equal_to + { static constexpr bool value = true; }; + + template requires (M < 0) || (N < 0) + struct equal_to + { }; +}; + +static_assert(traits<0>::equal_to<0>::value); +static_assert(!traits<0>::equal_to<1>::value); +static_assert(traits<-1>::equal_to<0>::value); // { dg-error "not a member" }