From patchwork Wed Apr 22 18:55:49 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1275368 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=pRAC3hLb; 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 496qQp5ZLjz9sSJ for ; Thu, 23 Apr 2020 04:56:16 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id B3E5F394742E; Wed, 22 Apr 2020 18:56:13 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org B3E5F394742E DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587581773; bh=OGnEbn0vrDOgz8Sq6MnhEjlmIgEMKoVZXGbJjBbTXQE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=pRAC3hLbcQaeUeltqYlMei6mH8JpeOAaBmgalYasxXDoRL2ct+Ulel52tE1lLnOGT MTKdeVB3+CwMHzY2DXLojUCIwkwn6DHh1NFCA4Wkpsan5aR0RijemceXcyVLHqSlS6 pZ3siQQgd3kLUO2ZrWOZWzaK+ce9XegUmZ1iP898= 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-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id 1C489385DC1F for ; Wed, 22 Apr 2020 18:56:11 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 1C489385DC1F Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-48-Kzr6Jd30PoOP6k0dLRhzTQ-1; Wed, 22 Apr 2020 14:56:07 -0400 X-MC-Unique: Kzr6Jd30PoOP6k0dLRhzTQ-1 Received: by mail-qk1-f199.google.com with SMTP id y64so3965960qkb.12 for ; Wed, 22 Apr 2020 11:56:07 -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=PbvcVLzx/wYL4SoYYgbkWXFGVJM1r+Zks3ZJuBMrk90=; b=cqBOiTqLh/v1Jwf+4ZPaijizSLQnGO9rp2P4H4KJWXTEs8jF8hwgqs5HPGtz2m8y1o rkl5aRHZZ5b/TZuZ4fD3Y8/pj5SfgYYIKmSkToVySfZzwnyff40E7sUPGGl5acmwW84D 7DQdKamAEGyKxdGEPZO3q52gOxlWfZpHg1aKaJnZpHTX2hEx5lc+8yvG5kMZF5ndSJDU asQGdmMyQCjJJnWMC7l7/friejN+9ybDbJYToQo+xZ+x17n0xzyUkfkGNvvKPVEsRtzC UOyGFTYbffsEY7LMuy46VwIjnUYww3oMzuPPc8N97n1jwFk2neJwQ71k8GnaRaZzbhLm reCg== X-Gm-Message-State: AGi0PubB7SfTL4q3sNKq1hVNWe80S2DmxwsHCG/GFVmLT2DKR4aOpNyx yNZx9n0Prf4C8TPlil8YNlcoBoSMnXkjGNq0Sl5X/zkcmSK6K0NZsYRyPud4DZwMfrIWKuLchgf 5ynZUvx3DgLA+hxbOeQ== X-Received: by 2002:a37:6754:: with SMTP id b81mr27872593qkc.129.1587581766389; Wed, 22 Apr 2020 11:56:06 -0700 (PDT) X-Google-Smtp-Source: APiQypIyRfU3Ij4yekgkHwmfFtXCIf6S426bhRy1zWA/iU5gKuujp5pv573wUeElaMnATAG3gbwrQA== X-Received: by 2002:a37:6754:: with SMTP id b81mr27872567qkc.129.1587581766081; Wed, 22 Apr 2020 11:56:06 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id q17sm39324qtk.84.2020.04.22.11.56.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 22 Apr 2020 11:56:05 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Inherited constructor template arguments [PR94719] Date: Wed, 22 Apr 2020 14:55:49 -0400 Message-Id: <20200422185549.2052667-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.2.108.g048abe1751 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.4 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, GIT_PATCH_1, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_NONE, 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" My fix for PR94549 broke constraints_satisfied_p in the case where the inherited constructor decl points to an instantiation of a constructor template coming from an instantiation of a class template. This is because the DECL_TI_ARGS of the inherited constructor decl in this case contains only the innermost level of template arguments (those for the constructor template), but constraint satisfaction expects to have the full set of template arguments. This causes template argument substitution to fail in various ways. On the the hand, the DECL_TI_ARGS of the DECL_INHERITED_CTOR is a full set of template arguments, but with the innermost level still in its dependent form, which is the source of PR94549. So if we could combine these two sets of template arguments then we'd be golden. This patch does just that, by effectively reverting the fix for PR94549 and instead using add_outermost_template_args to combine the template arguments of the inherited constructor with those of its DECL_INHERITED_CTOR. Bootstrapped and regtested successfully on x86_64-pc-linux-gnu, and also verified that the cmcstl2 testsuite now compiles successfully again. Does this look OK to commit? (The fact that the DECL_TI_ARGS of the inherited constructor decl doesn't contain the full set of template arguments seems to be inconsistent with the documentation for DECL_TI_ARGS, which says it is "always the full set of arguments required to instantiate this declaration from the most general template specialized here." But the full set of arguments for foo::bar<5> in the testcase below should be {{int},{5}}, not just {5}, I think?) gcc/cp/ChangeLog: PR c++/94719 PR c++/94549 * constraint.cc (satisfy_declaration_constraints): If an inherited constructor points to an instantiation of a constructor template, remember and use the attached template arguments. gcc/testsuite/ChangeLog: PR c++/94719 PR c++/94549 * g++.dg/cpp2a/concepts-inherit-ctor9.C: New test. --- gcc/cp/constraint.cc | 17 +++++++++++----- .../g++.dg/cpp2a/concepts-inherit-ctor9.C | 20 +++++++++++++++++++ 2 files changed, 32 insertions(+), 5 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index c05fafe5da1..06161b8c8c4 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2736,12 +2736,17 @@ static tree satisfy_declaration_constraints (tree t, subst_info info) { gcc_assert (DECL_P (t)); + const tree saved_t = t; - if (!DECL_TEMPLATE_INFO (t)) - /* For inherited constructors without template information, consider - the original declaration; it has the correct template information - attached. */ - t = strip_inheriting_ctors (t); + /* For inherited constructors, consider the original declaration; + it has the correct template information attached. */ + t = strip_inheriting_ctors (t); + tree inh_ctor_targs = NULL_TREE; + if (t != saved_t) + if (tree ti = DECL_TEMPLATE_INFO (saved_t)) + /* The inherited constructor points to an instantiation of a constructor + template; remember its template arguments. */ + inh_ctor_targs = TI_ARGS (ti); /* Update the declaration for diagnostics. */ info.in_decl = t; @@ -2761,6 +2766,8 @@ satisfy_declaration_constraints (tree t, subst_info info) /* The initial parameter mapping is the complete set of template arguments substituted into the declaration. */ args = TI_ARGS (ti); + if (inh_ctor_targs) + args = add_outermost_template_args (args, inh_ctor_targs); } else { diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C new file mode 100644 index 00000000000..7d3201bff9f --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor9.C @@ -0,0 +1,20 @@ +// PR c++/94719 +// { dg-do compile { target concepts } } + +template +struct bar +{ + template requires (N == 5) + bar() { } +}; + +template +struct foo : bar +{ + using foo::bar::bar; +}; + +void baz() +{ + foo{}; +}