From patchwork Thu Apr 23 20:09:47 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 1276007 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=ARWRegmW; 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 497T1Y0RCXz9sSK for ; Fri, 24 Apr 2020 06:10:09 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 30F94395C012; Thu, 23 Apr 2020 20:09:59 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 30F94395C012 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1587672599; bh=MbVEWyBlRk6oU61A+MejN1ZKCE8oMDG5hzy4fzqVatY=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=ARWRegmWPzgHPuMFcH+OcLp4B9Ld9Am8lOM9G9lSzna4B/xWFEaJi7KJVge3dRonf ga+hl28iuEdKbo7lvmXgR61mlwPfYL4dsu1etFa90b3ctynFaQEGm5oOq1NAZJOkKR ozP6y4wkel3FWQUiSX/3OQ5Dr5sKtM0OSVzvKk1o= 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 [205.139.110.120]) by sourceware.org (Postfix) with ESMTP id DA84C395BC3C for ; Thu, 23 Apr 2020 20:09:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org DA84C395BC3C Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) (Using TLS) by relay.mimecast.com with ESMTP id us-mta-370-uq2avj8dNzaMxaUzEPddWg-1; Thu, 23 Apr 2020 16:09:52 -0400 X-MC-Unique: uq2avj8dNzaMxaUzEPddWg-1 Received: by mail-qk1-f200.google.com with SMTP id a18so6885129qkl.0 for ; Thu, 23 Apr 2020 13:09:52 -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=M/z/21Wf+S1+ydKw0tNprMnY+BEI1BG3IipW/1NRnfM=; b=E1MZ3wsMLtZHXcDlIKFEe8sN1G23HcMTIEGoZxEm/qSQkO7NsR3kTUUJq4mrLIL9CP YT85OAx8AYbIWfKy5Xs64E14FdrhX7oSBLS1F6udArViMYAIfds6Pye7coOjp0eAyCxc sPaNvgpL9i3Tm4OGjl+QW9TJ1erBgAW0iuAE5L8O8hwzWMEUKH2/0PjzTNXTLfiIce38 T2P3f7s6PkK2jaQRcCZhSvRaS/tisStWmJo+aUucYElxvUJknbfmRdz2qXRScQdMSvfv M8NghGIJX+bBUFXNs1nUtJK/SzOpgp+5dDAGN81t2do5+qnOCy9EhejeH8Qjnc55q5Le aWiw== X-Gm-Message-State: AGi0PuZPW6mKilW0e6iXKAjy8L235wAQec2PhTGjb58FHKcBtOUIatxM pfmI7T8NRz0DZOhlUBNeJnmafeQ3NJkCNHjgSOAiQpfdsfTNe+KqpdnsbboX3CTtkmwXDCDjtq6 w3CHSxn9XE0FQKFWmAg== X-Received: by 2002:a05:620a:2f2:: with SMTP id a18mr5141776qko.261.1587672592110; Thu, 23 Apr 2020 13:09:52 -0700 (PDT) X-Google-Smtp-Source: APiQypJX78ZJVmgZVALGywUxJ/+5bDxDu41OgUoDjUfXTbhqWYPLU7m21U6pKElwZSDpt8hFrXySqg== X-Received: by 2002:a05:620a:2f2:: with SMTP id a18mr5141760qko.261.1587672591866; Thu, 23 Apr 2020 13:09:51 -0700 (PDT) Received: from localhost.localdomain (ool-457d493a.dyn.optonline.net. [69.125.73.58]) by smtp.gmail.com with ESMTPSA id u27sm2405891qtc.73.2020.04.23.13.09.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 23 Apr 2020 13:09:51 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [PATCH] c++: Lambda in friend of constrained class [PR94645] Date: Thu, 23 Apr 2020 16:09:47 -0400 Message-Id: <20200423200948.1949802-1-ppalka@redhat.com> X-Mailer: git-send-email 2.26.2.266.ge870325ee8 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" In the testcase below, when grokfndecl processes the operator() decl for the lambda inside the friend function foo, processing_template_decl is rightly 1, but template_class_depth on the lambda's closure type incorrectly returns 0 instead of 1. Since processing_template_decl > template_class_depth, this makes grokfndecl think that the operator() has its own set of template arguments, and so we attach the innermost set of constraints -- those belonging to struct l -- to the operator() decl. We then get confused when checking constraints_satisfied_p on the operator() because it doesn't have template information and yet has constraints associated with it. This patch fixes template_class_depth to return the correct template nesting level in cases like these, so that when it hits a friend function it walks into the DECL_FRIEND_CONTEXT of the friend rather than into the CP_DECL_CONTEXT. Bootstrapped and regtested on x86_64-pc-linux-gnu, and also tested on cmcstl2, range-v3, and fmt libraries. gcc/cp/ChangeLog: PR c++/94645 * pt.c (template_class_depth): Walk into the DECL_FRIEND_CONTEXT of a friend declaration rather than into its CP_DECL_CONTEXT. gcc/testsuite/ChangeLog: PR c++/94645 * g++.dg/cpp2a/concepts-lambda6.C: New test. --- gcc/cp/pt.c | 7 ++++++- gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C | 19 +++++++++++++++++++ 2 files changed, 25 insertions(+), 1 deletion(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C diff --git a/gcc/cp/pt.c b/gcc/cp/pt.c index 0e3e7b2039a..08a35c41007 100644 --- a/gcc/cp/pt.c +++ b/gcc/cp/pt.c @@ -390,7 +390,12 @@ template_class_depth (tree type) ++depth; if (DECL_P (type)) - type = CP_DECL_CONTEXT (type); + { + if (tree fctx = DECL_FRIEND_CONTEXT (type)) + type = fctx; + else + type = CP_DECL_CONTEXT (type); + } else if (LAMBDA_TYPE_P (type) && LAMBDA_TYPE_EXTRA_SCOPE (type)) type = LAMBDA_TYPE_EXTRA_SCOPE (type); else diff --git a/gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C new file mode 100644 index 00000000000..244421e64ec --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/concepts-lambda6.C @@ -0,0 +1,19 @@ +// PR c++/94632 +// { dg-do compile { target concepts } } + +struct unordered_map { + int cend() const noexcept; +}; + +template concept HasMapInterface = requires(a t) { t.cend(); }; + +template requires HasMapInterface +struct l { + friend void foo(l opt) { ([]() {})(); } +}; + +struct p { + static unordered_map map(); +}; + +void g(l

*y) { foo(*y); }