From patchwork Mon Apr 20 20:38:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1273721 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=bXcEXdBZ; 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 495dnw4RgXz9sP7 for ; Tue, 21 Apr 2020 06:38:42 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id EE882386F468; Mon, 20 Apr 2020 20:38:39 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org EE882386F468 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587415120; bh=iuxrPgwf1SiAmMyNFWnOhZQ75/gNpJDqbgK3P4bIE6s=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=bXcEXdBZCgxHLUoAQEnul4I+d3srPD/o257dMLI32TepLMDTksaTy9duwzXZcnVjI dBs2gcImTrmBb4FL1PB9/JvrrByfgL0dI7PdEm+lyKEFpEwd1uSl+l+yqJaUWUaqt+ Zf2f6/9sr3ab5WKhl+C10/6HL3j60JO/eLPvg2dg= X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-1.mimecast.com (us-smtp-2.mimecast.com [205.139.110.61]) by sourceware.org (Postfix) with ESMTP id ABC67386F45D for ; Mon, 20 Apr 2020 20:38:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org ABC67386F45D Received: from mail-qk1-f198.google.com (mail-qk1-f198.google.com [209.85.222.198]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-344-RIA_EpcxOR-644xU7odBXQ-1; Mon, 20 Apr 2020 16:38:34 -0400 X-MC-Unique: RIA_EpcxOR-644xU7odBXQ-1 Received: by mail-qk1-f198.google.com with SMTP id d1so11711319qkc.8 for ; Mon, 20 Apr 2020 13:38:34 -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=70O1aJ2wTHxautfo4PedB3RVIxqg7Lh14fgRD6RYeqg=; b=SYK9qOPEPS4NuZTjWPP9m9DHnrEVN6cZFvIjg12ApqLyPex8hqha0COx/yPF66B4J2 g44Olk94WvOSZc39Q7NtcPuV0s1HTIHAiaEULTQTRACwIJbFyAUIczHI37jdKkfcQR81 rQdu3AOZvkfBWbUnEkHafHKfw9+LQQdLilXYVcGkRd0c2HzdlTSi/Ox4LOK2pRqUzUX/ kI9WLH+9tNHQe5VxwfvU/bjNpW+jFXgiFjMy0nxSbYMgVq4adBJTqzAkwGarWBcEkKJS SsWKSjPw0FLBB6KQ/WAkw/B8yfN1aFI9/Js9qRFCKu6BV3mF4DFMP5CFmGhZYlTNUpwZ bRNQ== X-Gm-Message-State: AGi0PubWEXx5Xd1/m3iaUCz89nkxO99RbHe2wPUu/Ys7uZfxB3fQVahA dbxY5yBqiJQ4KSpifH63fnXEFin15OIxvjCtLZCIKuYQgfOlPvdDazA3z2IzaEM8w8mMJ7kopcD CxfdDKlKwYSwlSpC5aQ== X-Received: by 2002:ac8:922:: with SMTP id t31mr17003797qth.95.1587415113357; Mon, 20 Apr 2020 13:38:33 -0700 (PDT) X-Google-Smtp-Source: APiQypKXUpWrHMKv1gEBHIUvmDdKADUgQ2hB8MxnBMk2GXGDPJhKWGh45hn1ZPJ+Kk3oOdG4WWJ8ug== X-Received: by 2002:ac8:922:: with SMTP id t31mr17003771qth.95.1587415112988; Mon, 20 Apr 2020 13:38:32 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id e133sm429697qkb.128.2020.04.20.13.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 20 Apr 2020 13:38:31 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Constrained inherited constructor template [PR94549] Date: Mon, 20 Apr 2020 16:38:30 -0400 Message-Id: <20200420203830.3660750-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.1.107.gefe3874640 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-28.5 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" A comment in satisfy_declaration constraints says /* For inherited constructors, consider the original declaration; it has the correct template information attached. */ d = strip_inheriting_ctors (d); But this comment seems to be false when the inherited constructor points to an instantiation of a constructor template. In this case, DECL_TEMPLATE_INFO is correct and DECL_INHERITED_CTOR points to the constructor template of the base class rather than to the particular instantiation of the constructor template (and so the DECL_TI_ARGS of the DECL_INHERITED_CTOR are in their dependent form). So doing strip_inheriting_ctors in this case then eventually leads to satisfy_associated_constraints returning true regardless of the constraints themselves, due to the passed in 'args' being dependent. Since DECL_TEMPLATE_INFO seems to be non-NULL for an inherited constructor only when the inherited constructor points to an instantiation of a constructor template, this patch fixes this issue by avoiding to call strip_inheriting_ctors when DECL_TEMPLATE_INFO is already non-NULL. There is another unguarded call to strip_inheriting_ctors in get_normalized_constraints_from_decl, but this one seems to be safe to do unconditionally because the rest of that function doesn't need/look at the DECL_TI_ARGS of the decl. Passes 'make check-c++', does this look OK to commit after bootstrap/regtesting? gcc/cp/ChangeLog: PR c++/94549 * constraint.cc (satisfy_declaration_constraints): Don't strip the inherited constructor if it already has template information. gcc/testsuite/ChangeLog: PR c++/94549 * g++.dg/concepts/inherit-ctor3.C: Adjust expected diagnostics. * g++.dg/cpp2a/concepts-inherit-ctor4.C: Adjust expected diagnostics. * g++.dg/cpp2a/concepts-inherit-ctor8.C: New test. --- gcc/cp/constraint.cc | 7 ++++--- gcc/testsuite/g++.dg/concepts/inherit-ctor3.C | 4 ++-- .../g++.dg/cpp2a/concepts-inherit-ctor4.C | 4 ++-- .../g++.dg/cpp2a/concepts-inherit-ctor8.C | 20 +++++++++++++++++++ 4 files changed, 28 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor8.C diff --git a/gcc/cp/constraint.cc b/gcc/cp/constraint.cc index 320792195d6..b76402c2f85 100644 --- a/gcc/cp/constraint.cc +++ b/gcc/cp/constraint.cc @@ -2737,9 +2737,10 @@ satisfy_declaration_constraints (tree t, subst_info info) { gcc_assert (DECL_P (t)); - /* For inherited constructors, consider the original declaration; - it has the correct template information attached. */ - if (flag_new_inheriting_ctors) + 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); /* Update the declaration for diagnostics. */ diff --git a/gcc/testsuite/g++.dg/concepts/inherit-ctor3.C b/gcc/testsuite/g++.dg/concepts/inherit-ctor3.C index abfe96e8240..6b7a7a43910 100644 --- a/gcc/testsuite/g++.dg/concepts/inherit-ctor3.C +++ b/gcc/testsuite/g++.dg/concepts/inherit-ctor3.C @@ -12,12 +12,12 @@ template template struct S2 : S1 { // { dg-error "no matching function" } - using S1::S1; // { dg-error "no matching function" } + using S1::S1; }; struct X { } x; int main() { - S2 s1(0); // { dg-error "use of deleted function" } + S2 s1(0); // { dg-error "no matching function" } S2 s2; // { dg-error "use of deleted function" } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor4.C b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor4.C index 75190eb3413..34eaf22c26c 100644 --- a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor4.C +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor4.C @@ -10,9 +10,9 @@ template template struct S2 : S1 { - using S1::S1; // { dg-error "no matching function" } + using S1::S1; }; int main() { - S2 s(0); // { dg-error "use of deleted function" } + S2 s(0); // { dg-error "no matching function" } } diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor8.C b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor8.C new file mode 100644 index 00000000000..5b571e32318 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-inherit-ctor8.C @@ -0,0 +1,20 @@ +// PR c++/94549 +// { dg-do compile { target concepts } } + +struct base { + template + requires false + base(type); + + template + requires true + base(type); +}; + +struct derived : base { + using base::base; +}; + +void foo() { + derived{'G'}; +}