From patchwork Fri Jun 3 17:44:31 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1638807 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.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=QExY3ZSQ; dkim-atps=neutral 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+incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=) 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 (2048 bits) server-digest SHA256) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4LF9KH3bRxz9s09 for ; Sat, 4 Jun 2022 03:45:55 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E0624384B07F for ; Fri, 3 Jun 2022 17:45:52 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org E0624384B07F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1654278352; bh=qN7a+l7Af1ZKAQKvihFqinQxUDocGl/bS2rcUTwJpTc=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=QExY3ZSQvlJmNRZyPgMox5XVjAmoC7BqCtJ10EJn7XBrdjon7VQkMu42MoeL5oKW1 T6QzgGwChs3L+WmjHUoFyc+gL+sKoS6jv86Seh3zgdM4B9u64cuhw7+sonZuXWG8C5 VA5sXS19w3Uwx5xeZ8GJxsRoIU3+XYHrlaKx9mQE= 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.129.124]) by sourceware.org (Postfix) with ESMTPS id 20542384B07F for ; Fri, 3 Jun 2022 17:44:37 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 20542384B07F Received: from mail-qt1-f199.google.com (mail-qt1-f199.google.com [209.85.160.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id us-mta-425-ZLG8aFArP9ygZu9Tuyg4HA-1; Fri, 03 Jun 2022 13:44:35 -0400 X-MC-Unique: ZLG8aFArP9ygZu9Tuyg4HA-1 Received: by mail-qt1-f199.google.com with SMTP id u17-20020a05622a14d100b00304cf9c24fdso4454477qtx.7 for ; Fri, 03 Jun 2022 10:44:35 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:mime-version :content-transfer-encoding; bh=qN7a+l7Af1ZKAQKvihFqinQxUDocGl/bS2rcUTwJpTc=; b=Zi6K2OO2WFG7UwOls/EO/4YqvV8P+wFihYA+Iq/xtzuZGr20Yw8fxbdrRK6IOP2AZj mODtsiP8ENPr7SwlfEa5NDENMUJBL73XXGC/1axCQXympay7DRP3VzTFHuo0tjuxDqti uxW8bR+i6uOnqDqweNOQuDoqiRQxe+k0+ZL1lPMKAjJ4twCGT2ECnL4T2r/GjVyVc9Rd UNp/3wzOUhPbylxBBlhLL0uG5iyebnL0asRmTDMR6trM9TcnBOVv3uhYbWQ5gbNR7h0O 8Kl9tt7DGGF58gw2fdgaEUPcs7RA42Nl5YEiFHs65gZbLW+NgL514UlGRGdJHgz3fkjg RM0Q== X-Gm-Message-State: AOAM530daRN3+40zBj5XrCkdl+tL8Xp86z64GX8wPkoZkKR/JMhhJCec SWInwSnSTW3GuJrWBHvEeTZJgrZyp6LpWRxHgpyYRMLq3A2fCLEnxxLWibl6jYZGrp1mrgmHi6h OvcDZRwah26wkG5IrQUWDJC6cKVJrwbL9HaXy/5gpb9/BuK5gQMWIz29+VXufBXnRcg== X-Received: by 2002:a05:622a:1308:b0:304:b3d5:15ae with SMTP id v8-20020a05622a130800b00304b3d515aemr8434725qtk.252.1654278274721; Fri, 03 Jun 2022 10:44:34 -0700 (PDT) X-Google-Smtp-Source: ABdhPJy6lROBzrx/O+XZVK2WTzgnn7J4arVK0BSs2b02dgI5nmp+uoPRiugx2KaDFLdrTf+FNy9sUQ== X-Received: by 2002:a05:622a:1308:b0:304:b3d5:15ae with SMTP id v8-20020a05622a130800b00304b3d515aemr8434699qtk.252.1654278274235; Fri, 03 Jun 2022 10:44:34 -0700 (PDT) Received: from barrymore.redhat.com (130-44-159-43.s15913.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.159.43]) by smtp.gmail.com with ESMTPSA id o17-20020ac84291000000b00304defdb1b3sm1590916qtl.85.2022.06.03.10.44.33 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 03 Jun 2022 10:44:33 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: redeclared hidden friend [PR105761] Date: Fri, 3 Jun 2022 13:44:31 -0400 Message-Id: <20220603174431.2007386-1-jason@redhat.com> X-Mailer: git-send-email 2.27.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-13.1 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: Jason Merrill via Gcc-patches From: Jason Merrill Reply-To: Jason Merrill Errors-To: gcc-patches-bounces+incoming=patchwork.ozlabs.org@gcc.gnu.org Sender: "Gcc-patches" Here, when we see the second declaration of f we match it with the first one, copy over DECL_TEMPLATE_INFO, and then try to use it when parsing the definition, leading to confusion. Tested x86_64-pc-linux-gnu, applying to trunk. PR c++/105761 gcc/cp/ChangeLog: * decl.cc (duplicate_decls): Don't copy DECL_TEMPLATE_INFO from a hidden friend. gcc/testsuite/ChangeLog: * g++.dg/cpp1y/auto-fn64.C: New test. --- gcc/cp/decl.cc | 12 ++++++++++-- gcc/testsuite/g++.dg/cpp1y/auto-fn64.C | 12 ++++++++++++ 2 files changed, 22 insertions(+), 2 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp1y/auto-fn64.C base-commit: 1982fe2692b6c3b7f969ffc4edac59f9d4359e91 diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index e0d397d5a07..90b12d69414 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -2654,7 +2654,13 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) if (LANG_DECL_HAS_MIN (newdecl)) { DECL_ACCESS (newdecl) = DECL_ACCESS (olddecl); - if (DECL_TEMPLATE_INFO (newdecl)) + if (new_defines_function + && DECL_TEMPLATE_INFO (olddecl) + && DECL_UNIQUE_FRIEND_P (DECL_TEMPLATE_RESULT + (DECL_TI_TEMPLATE (olddecl)))) + /* Don't copy template info from a non-template friend declaration + in a class template (PR105761). */; + else if (DECL_TEMPLATE_INFO (newdecl)) { new_template_info = DECL_TEMPLATE_INFO (newdecl); if (DECL_TEMPLATE_INSTANTIATION (olddecl) @@ -2662,8 +2668,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) /* Remember the presence of explicit specialization args. */ TINFO_USED_TEMPLATE_ID (DECL_TEMPLATE_INFO (olddecl)) = TINFO_USED_TEMPLATE_ID (new_template_info); + DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); } - DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); + else + DECL_TEMPLATE_INFO (newdecl) = DECL_TEMPLATE_INFO (olddecl); } if (DECL_DECLARES_FUNCTION_P (newdecl)) diff --git a/gcc/testsuite/g++.dg/cpp1y/auto-fn64.C b/gcc/testsuite/g++.dg/cpp1y/auto-fn64.C new file mode 100644 index 00000000000..13f3175da45 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp1y/auto-fn64.C @@ -0,0 +1,12 @@ +// PR c++/105761 +// { dg-do compile { target c++14 } } +// { dg-additional-options -Wno-non-template-friend } + +template +class X { + friend auto f(X); +}; + +struct Y : X { + friend auto f(X) { return 0L; } +};