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: 1789686 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) Authentication-Results: legolas.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=inBrzmth; 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 ECDSA (P-384) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4QXll16gZrz20QH for ; Sat, 3 Jun 2023 00:29:49 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id BE94A385781F for ; Fri, 2 Jun 2023 14:29:47 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org BE94A385781F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1685716187; 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=inBrzmthJEDuO9qIz81EMltH25gZtHrMTnan84O7IfeJGeGe9DhygXRNGATA/p5Iu c4DtbE7kuQJQTAQefiphmxXiM9vAmRJzs13nwatT7jDA6cDgLF1z1+sEcDD0X7dHJE C9c4MRo1zdBAyuFnZK+mRvGhKYxd6LUpReN2XboA= 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-Google-Smtp-Source: ACHHUZ6MZiLwA6wGSU+1sK7zSsXQcmLZ48R/SP1huQWm1iJ3ICj7CHpt1iXR5oixfdJlgKzSydb6TA== 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+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" 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" } +}