From patchwork Fri Sep 18 20:07:26 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1367283 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=8.43.85.97; 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=uhrpQp10; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4BtPyK4bTlz9sSW for ; Sat, 19 Sep 2020 06:07:37 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BC12338618F1; Fri, 18 Sep 2020 20:07:34 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BC12338618F1 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1600459654; bh=ePS799/WuVXtrY9p4x+3KowPmGg7tCuxcvZA7vzYf7g=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:Cc:From; b=uhrpQp10HIYZgGhaFrjPS3kp0V5RmHnNU/pNTe5KqKwaxSB4JMqCZTOauELsjxrJh BGdfq/OKgZtcQbntDMD3pn9llxgEo60QE4MEpDox8VO7+MvsRhg4UnryTVfkg0Yjk9 esgx9peDS8nR1yCdtWVWc7vBsT0Z/AiZHrNpilbY= 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 F0BF138618F1 for ; Fri, 18 Sep 2020 20:07:31 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org F0BF138618F1 Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-545-AwRQkaa1MdaTWEGHqf4soA-1; Fri, 18 Sep 2020 16:07:30 -0400 X-MC-Unique: AwRQkaa1MdaTWEGHqf4soA-1 Received: by mail-qt1-f198.google.com with SMTP id y53so6112543qth.2 for ; Fri, 18 Sep 2020 13:07:29 -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=ePS799/WuVXtrY9p4x+3KowPmGg7tCuxcvZA7vzYf7g=; b=d/oOzhY1XnMBhq6goerDp6LNTwhdDo2vC5L1oV/lOGNsYYKWxSqcnppyOXw1b45eyu bYXu5wsHpM9/52Z2qm4ZHHe1paVSGsVeve8Ojh9e/G+xlm4z/eI1xF9gCJVsPHBF8qGx YJgrLFbpZontehJUlVdGIcchcqoL2ZA8Z+ET9wWB/KwtuQLUUqrNM+KffHFCdpzcJhAw lrT/4xM6bPBylTmPnmhBR+QY9UbskkSgpmk4rk7hBC0gHN3UbnCVvrusaXAvprzNy12Q azKByMNu2Ja3cGDg+Mrq7+MifT1GBlbZEBRodCdzuVtter8htGeskC1Kd70bL3EKYMDd GwIw== X-Gm-Message-State: AOAM532u+vGvkEr+Urigbh+RElpaOCoDHV+Nl48pAsirWnqObLK+ki1f pD17ZB0cQyzLzVmpMW+XIbZCsyMyYKRhg5o0vSeDRMcPenRWfDtYXBfvG/tj25QejLv63fX4Zw8 8VL+NhwiQUR0Dum4hrg== X-Received: by 2002:ac8:24b9:: with SMTP id s54mr33877149qts.138.1600459648979; Fri, 18 Sep 2020 13:07:28 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx5/r0tANg7lSsjPtk2IeWFhWBC9/LA6hCMAMt1grbn4d106GnECOqWeCjTqplSv/fRK4t//w== X-Received: by 2002:ac8:24b9:: with SMTP id s54mr33877115qts.138.1600459648602; Fri, 18 Sep 2020 13:07:28 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id 85sm2808908qkn.64.2020.09.18.13.07.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 18 Sep 2020 13:07:27 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Fix self-mapping in map_arguments [PR96531, PR97103] Date: Fri, 18 Sep 2020 16:07:26 -0400 Message-Id: <20200918200726.2123779-1-ppalka@redhat.com> X-Mailer: git-send-email 2.28.0.497.g54e85e7af1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-17.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_NONE, RCVD_IN_MSPIKE_H5, 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 Cc: nathan@acm.org Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" With r10-8077 we stopped passing the argified current_template_parms to normalize_constraint_expression from finish_nested_requirement, and instead tweaked map_arguments to perform a self-mapping of parameters when args is NULL. We're currently not handling parameter packs and BOUND_TEMPLATE_TEMPLATE_PARMs properly during this self-mapping, which leads to ICEs later during satisfaction. To fix the self-mapping of a parameter pack, this patch makes map_arguments use template_parm_to_arg which already does the right thing for parameter packs. Before r10-8077, a BOUND_TEMPLATE_TEMPLATE_PARM would get mapped to the corresponding TEMPLATE_TEMPLATE_PARM. We could restore this behavior in map_arguments, but since a BOUND_TEMPLATE_TEMPLATE_PARM is not really a template parameter it seems better to make keep_template_parm not give us a BOUND_TEMPLATE_TEMPLATE_PARM in the first place. I think what we actually want is to map the TEMPLATE_TEMPLATE_PARM to itself, so this patch adjusts keep_template_parm to give us the corresponding TEMPLATE_TEMPLATE_PARM of a BOUND_TEMPLATE_TEMPLATE_PARM instead. Tested on x86_64-pc-linux-gnu, and also tested with the cmcstl2 library. Does this look OK for trunk/10? gcc/cp/ChangeLog: PR c++/96531 PR c++/97103 * constraint.cc (map_arguments): Call template_parm_to_arg appropriately when doing a self-mapping. * pt.c (keep_template_parm): Don't record a BOUND_TEMPLATE_TEMPLATE_PARM, instead record its corresponding TEMPLATE_TEMPLATE_PARM. gcc/testsuite/ChangeLog: PR c++/96531 PR c++/97103 * g++.dg/cpp2a/concepts-ttp2.C: New test. * g++.dg/cpp2a/concepts-variadic1.C: New test. --- gcc/cp/constraint.cc | 27 ++++++++++++------ gcc/cp/pt.c | 5 ++++ gcc/testsuite/g++.dg/cpp2a/concepts-ttp2.C | 11 ++++++++ .../g++.dg/cpp2a/concepts-variadic1.C | 28 +++++++++++++++++++ 4 files changed, 62 insertions(+), 9 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-ttp2.C create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-variadic1.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 0aab3073cc1..43336d191d9 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -546,15 +546,24 @@ static tree map_arguments (tree parms, tree args) { for (tree p = parms; p; p = TREE_CHAIN (p)) - if (args) - { - int level; - int index; - template_parm_level_and_index (TREE_VALUE (p), &level, &index); - TREE_PURPOSE (p) = TMPL_ARG (args, level, index); - } - else - TREE_PURPOSE (p) = TREE_VALUE (p); + { + tree parm = TREE_VALUE (p); + if (args) + { + int level; + int index; + template_parm_level_and_index (parm, &level, &index); + TREE_PURPOSE (p) = TMPL_ARG (args, level, index); + } + else + { + tree tpi = (TYPE_P (parm) + ? TEMPLATE_TYPE_PARM_INDEX (parm) : parm); + TREE_PURPOSE (p) + = template_parm_to_arg (build_tree_list (NULL_TREE, + TEMPLATE_PARM_DECL (tpi))); + } + } return parms; } diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index cfe5ff4a94f..55d8060b911 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -10539,6 +10539,11 @@ keep_template_parm (tree t, void* data) if (level > ftpi->max_depth) return 0; + if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) + /* A BOUND_TEMPLATE_TEMPLATE_PARM isn't a template parameter. What we + really want is the corresponding TEMPLATE_TEMPLATE_PARM. */ + t = TREE_TYPE (TEMPLATE_TEMPLATE_PARM_TEMPLATE_DECL (t)); + /* Arguments like const T yield parameters like const T. This means that a template-id like X would yield two distinct parameters: T and const T. Adjust types to their unqualified versions. */ diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-ttp2.C b/gcc/testsuite/g++.dg/cpp2a/concepts-ttp2.C new file mode 100644 index 00000000000..7f4883754dd --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-ttp2.C @@ -0,0 +1,11 @@ +// PR c++/97103 +// { dg-do compile { target c++20 } } + +template +class quantity {}; + +template typename Q> +inline constexpr bool valid_template_arguments = requires { + requires requires { typename Q; }; +}; +static_assert(valid_template_arguments); diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-variadic1.C b/gcc/testsuite/g++.dg/cpp2a/concepts-variadic1.C new file mode 100644 index 00000000000..deab028ca3c --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-variadic1.C @@ -0,0 +1,28 @@ +// PR c++/96531 +// { dg-do compile { target c++20 } } + +template +concept is_bool = __is_same(bool, T); + +template +concept C = requires { + requires (is_bool || ...); +}; + +template +concept D = requires { + requires (Bs || ...); +}; + +template +requires C +void bar() {} + +template +requires D +void baz() {} + +int main() { + bar(); + baz(); +}