From patchwork Fri Jun 2 14:29:20 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Palka X-Patchwork-Id: 102578 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:994d:0:b0:3d9:f83d:47d9 with SMTP id k13csp1070199vqr; Fri, 2 Jun 2023 07:30:13 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ4SaNXaU7100XglUdSCGahRNizaFm7FUe380nHxhOcNXk5o9uVWvgnBON9fJiraLrh4ck9y X-Received: by 2002:a17:907:eaa:b0:94f:7edf:8fa1 with SMTP id ho42-20020a1709070eaa00b0094f7edf8fa1mr11388865ejc.32.1685716213634; Fri, 02 Jun 2023 07:30:13 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1685716213; cv=none; d=google.com; s=arc-20160816; b=y3Cxy+7CNHWdLkvHpJzYBXK5+wVnyYWTTXCY+3asKhncj5jZYGcoK8XxzJdNiwyiMK l+giYoWAJvQkrbqltyegAad1Srdesp7jz5gh9qHbRCCJkxEWil3fySSpyhxa26lH+nyF TisurHLT87aQuAp0x0IAwWnE9ZiTvYMPL/3QWs+PBM5ipxFhrfAA6suWp9KPZCoTeeLF eOYT0jSAjxII9o3BZod70Wwo3tOR1DJz/dx0YBBymFe9WfTzROhHNvrsO9bgOPYk8e/4 Mgyh0VaH7R0Kozsgb1jreWfuWoD9fPJfNYr5xS25l/B0PgQ5IxhgHmGtCPgZ3qKGPYST d8PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:reply-to:from:list-subscribe:list-help:list-post :list-archive:list-unsubscribe:list-id:precedence :content-transfer-encoding:mime-version:message-id:date:subject:cc :to:dmarc-filter:delivered-to:dkim-signature:dkim-filter; bh=Rdv/q9fdLT48oLnWEx65QD9j1lW1nzrccE1EIiZ1kJI=; b=JcP+6ybHX47TOaeV39st733Yz3LjQcgJNjzYcUjeNGtuD5SCSUX6Bi+3bPpRulkUXU Zsz8u9WuyBqBziGfAPJG3m7qNRZF3UuZJG30w4Jh9xquNRxZ0AcbhZ3vpPfiAh4e07Zu DVBFK45Um86Wnsxyq0uycxgX/V9Ag9rrrAAyMcoGKN4b4Br1uhcJwHTmV/ifGJ6H5ace hmqoEMMZQ5xSBloEdSRamUD2esTW4DORV+7cQHOa+C/Qu1fhqb6pYG8aLWQKjesS6u5k gKLJVHQa5XEnhf5K0cksvukIFWC1eq0v71+kttgjgGua5GFSbZtKvdCwC3RntIlVU1Lt EYLA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UiO9hOPg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from sourceware.org (server2.sourceware.org. [8.43.85.97]) by mx.google.com with ESMTPS id de30-20020a1709069bde00b0096b48d52ff4si932324ejc.608.2023.06.02.07.30.13 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 07:30:13 -0700 (PDT) Received-SPF: pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) client-ip=8.43.85.97; Authentication-Results: mx.google.com; dkim=pass header.i=@gcc.gnu.org header.s=default header.b=UiO9hOPg; spf=pass (google.com: domain of gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org designates 8.43.85.97 as permitted sender) smtp.mailfrom="gcc-patches-bounces+ouuuleilei=gmail.com@gcc.gnu.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=gnu.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 8B6F93857BB2 for ; Fri, 2 Jun 2023 14:30:12 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 8B6F93857BB2 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685716212; bh=Rdv/q9fdLT48oLnWEx65QD9j1lW1nzrccE1EIiZ1kJI=; h=To:Cc:Subject:Date:List-Id:List-Unsubscribe:List-Archive: List-Post:List-Help:List-Subscribe:From:Reply-To:From; b=UiO9hOPgUUmW/eNJ7LA4rBCWJ+qFVqM/Mt5YW9xQZCln4dCoGGCL1Eh9ZnDP+l5DC 2H4aH3CgjCi7/RXn9lTV+Hw5nODoS4tgSsAaAHQA6DM+3Lbw0VEAbtVnIcIHE7qsAm X3fPhsqGzTFCXm/0d7QOulfLJNgLpKjA136CXHQ4= 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 [170.10.133.124]) by sourceware.org (Postfix) with ESMTPS id 9B3AD3858D32 for ; Fri, 2 Jun 2023 14:29:26 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 9B3AD3858D32 Received: from mail-qv1-f69.google.com (mail-qv1-f69.google.com [209.85.219.69]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-424-u_vSHs_pObSykBhIT0wNpQ-1; Fri, 02 Jun 2023 10:29:25 -0400 X-MC-Unique: u_vSHs_pObSykBhIT0wNpQ-1 Received: by mail-qv1-f69.google.com with SMTP id 6a1803df08f44-629b6d2b336so3301846d6.0 for ; Fri, 02 Jun 2023 07:29:24 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1685716164; x=1688308164; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=Rdv/q9fdLT48oLnWEx65QD9j1lW1nzrccE1EIiZ1kJI=; b=Jb2UGPKByqMJu5uI1iUVJSgj/Fb003BaCEAZkIIg4ABbgNcVrKgUPoAa4o+vUMFYCp hQSrs75xKkoaD98ZeTabux9KFRM7CARszIaW6Hi3ms6HaVa5GEvCX8AjpfgMwL21b0Jz I5sWmEnHZllqhvxzcUx8yl3F4ivqcI9FFOHFVRTE/71GxM/f/rUtpEYvZc5LA4SUd2XR QySyDDHwV79ireh7umbyEkNZlbkSMxsJJF0ObEGknc0tNruUFTnxkQGPWfINJAGyxnl6 94oMEA9y4/EvBOzpFhHJvoUVVAXt/zoEovBqev3v8JMqfgS7iH5vxi+4V6vceSun1alO 4OoA== X-Gm-Message-State: AC+VfDzFz7CYqLUyJ+xN9fccbVJwLXnQr3AakfLj5khu9wFHlxNp9Of/ qkRj0FqZsZLP1J4zTVAwhbpa+9I+ybujpHFVKgSir0aj1mmbXYMatHaKDT0dvQWBg94Z4o57Pc2 w5p/kpb6Hh9Y6wbpyZ+PY+xYYAtxxXPsBtm+v01zy7XB0nwOdvLwDzbdnf4/1Fz0Hx9R9O35ixx E= X-Received: by 2002:ad4:5e86:0:b0:628:8185:bd6e with SMTP id jl6-20020ad45e86000000b006288185bd6emr3126448qvb.5.1685716164103; Fri, 02 Jun 2023 07:29:24 -0700 (PDT) X-Received: by 2002:ad4:5e86:0:b0:628:8185:bd6e with SMTP id jl6-20020ad45e86000000b006288185bd6emr3126425qvb.5.1685716163768; Fri, 02 Jun 2023 07:29:23 -0700 (PDT) Received: from localhost.localdomain (ool-457670bb.dyn.optonline.net. [69.118.112.187]) by smtp.gmail.com with ESMTPSA id ew19-20020a0562140ab300b006263784674esm896073qvb.14.2023.06.02.07.29.23 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 02 Jun 2023 07:29:23 -0700 (PDT) To: gcc-patches@gcc.gnu.org Cc: jason@redhat.com, Patrick Palka Subject: [PATCH] c++: is_specialization_of_friend confusion [PR109923] Date: Fri, 2 Jun 2023 10:29:20 -0400 Message-ID: <20230602142920.1793173-1-ppalka@redhat.com> X-Mailer: git-send-email 2.41.0.rc1.10.g9e49351c30 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.8 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, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) 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+ouuuleilei=gmail.com@gcc.gnu.org Sender: "Gcc-patches" X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1767601564273332321?= X-GMAIL-MSGID: =?utf-8?q?1767601564273332321?= Bootstrapped and regtested on x86_64-pc-linux-gnu, does this look OK for trunk? -- >8 -- The check for a non-template member function of a class template in is_specialization_of_friend is overbroad, and accidentally holds for a non-template hidden friend too, which causes the predicate to return true for decl = void non_templ_friend(A, A) friend_decl = void non_templ_friend(A, A) This patch refines the check appropriately. PR c++/109923 gcc/cp/ChangeLog: * pt.cc (is_specialization_of_friend): Fix overbroad check for a non-template member function of a class template. gcc/testsuite/ChangeLog: * g++.dg/template/friend79.C: New test. --- gcc/cp/pt.cc | 1 + gcc/testsuite/g++.dg/template/friend79.C | 20 ++++++++++++++++++++ 2 files changed, 21 insertions(+) create mode 100644 gcc/testsuite/g++.dg/template/friend79.C diff --git a/gcc/cp/pt.cc b/gcc/cp/pt.cc index 7c2a5647665..a15d1d062c6 100644 --- a/gcc/cp/pt.cc +++ b/gcc/cp/pt.cc @@ -1319,6 +1319,7 @@ is_specialization_of_friend (tree decl, tree friend_decl) of a template class, we want to check if DECL is a specialization if this. */ if (TREE_CODE (friend_decl) == FUNCTION_DECL + && DECL_CLASS_SCOPE_P (friend_decl) && DECL_TEMPLATE_INFO (friend_decl) && !DECL_USE_TEMPLATE (friend_decl)) { diff --git a/gcc/testsuite/g++.dg/template/friend79.C b/gcc/testsuite/g++.dg/template/friend79.C new file mode 100644 index 00000000000..cd2030df019 --- /dev/null +++ b/gcc/testsuite/g++.dg/template/friend79.C @@ -0,0 +1,20 @@ +// PR c++/109923 + +template +struct A { +private: + int x; + +public: + A() : x(0) { } + + friend void non_templ_friend(A val, A weird) { + val.x++; // always works + weird.x++; // { dg-error "private" } should only work when T=void + } +}; + +int main() { + non_templ_friend(A(), A()); // { dg-bogus "" } + non_templ_friend(A(), A()); // { dg-message "required from here" } +}