From patchwork Tue Apr 4 03:22:48 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1764677 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=k06yE8wE; 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 4PrClJ1hv9z1yZY for ; Tue, 4 Apr 2023 13:23:22 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 9C66C385840D for ; Tue, 4 Apr 2023 03:23:20 +0000 (GMT) DKIM-Filter: OpenDKIM Filter v2.11.0 sourceware.org 9C66C385840D DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gcc.gnu.org; s=default; t=1680578600; bh=RvWF2HbfXo5o19TN1yT756ajPCzMGiHLUNa1mTZbxNE=; h=To:Subject:Date:List-Id:List-Unsubscribe:List-Archive:List-Post: List-Help:List-Subscribe:From:Reply-To:From; b=k06yE8wEWm/OO/bff6KyZbk0QCp1gr7HQILJk9DYzsAJrB+dWL1yOPIByPjgCMyyG g3pqrxLMJcd2kG5+AM+7Mr54Bg9TRqYRe+jRAvns5E9qSy2bAEt/830c57LvxkudS1 mB2w3GZitPp4Koa9Jlaw+1OfOzaPAXlC0x7w+ESs= 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 480FA3858D1E for ; Tue, 4 Apr 2023 03:23:00 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 480FA3858D1E Received: from mail-qk1-f200.google.com (mail-qk1-f200.google.com [209.85.222.200]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-512-yEiREujGOfi5DxWKL8fLxQ-1; Mon, 03 Apr 2023 23:22:58 -0400 X-MC-Unique: yEiREujGOfi5DxWKL8fLxQ-1 Received: by mail-qk1-f200.google.com with SMTP id n129-20020a374087000000b0074a2ff16363so2877819qka.1 for ; Mon, 03 Apr 2023 20:22:58 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680578578; h=content-transfer-encoding:mime-version:message-id:date:subject:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=RvWF2HbfXo5o19TN1yT756ajPCzMGiHLUNa1mTZbxNE=; b=MZ0aOdIYT2uvE1qmf6JrqyLFkl6jUyNojClR+QQLbfuyUIEG1c2jOnBPqBcOPeXnxC /8J06awnoilYgdzinFCUuZhw6v9dx43GwCrurexkpbqgqNQ5ha7FC2oCV2/l2OnBz5Ds eqjWnrGFG+tHYP7uy1cQIwINCfy1J01uXgMPg6PPazAMkmqlvrartwZPlLiZ8kfQK5Qr TTA9GQ6wyqvp99uTMY0KJD7gK5vgkWcsXtDR3k5U5nnB8ztbnczGShVT5hTqvwoUpakJ VeakMzZXldsNMprkCIH9bkJvnANQHhZcOz1EYt+wOR0fGo0jds2ENQSDBWqc96NpC16y BHDQ== X-Gm-Message-State: AAQBX9dXqCBwksCzJsjmhBisjOhruqpSF671usoAVvTBTvHtzVUxxVc0 gXskS/zl2RnPXWR1wlqrJLIyjlzV/KnWy8EeDV7P+hQAylSkvoP7tb0R+XnWkrVU8mPw50Q/fgv 1wN4LlQmcI1SVCWkYw8niuxKU910ZChp44VehHMgYE5yCDVe8pxY3qLj0ABrjPBFJ5jBPGE9ZxA == X-Received: by 2002:ac8:5c87:0:b0:3d9:45a4:e7b9 with SMTP id r7-20020ac85c87000000b003d945a4e7b9mr1162263qta.45.1680578577931; Mon, 03 Apr 2023 20:22:57 -0700 (PDT) X-Google-Smtp-Source: AKy350ZaCsSb+44PIQdCL1FtTjC/TM+XTVWE0ilZTOcWUlL8D1gDlNSnR/d2hI7AG+QPvQZds8Cytg== X-Received: by 2002:ac8:5c87:0:b0:3d9:45a4:e7b9 with SMTP id r7-20020ac85c87000000b003d945a4e7b9mr1162245qta.45.1680578577495; Mon, 03 Apr 2023 20:22:57 -0700 (PDT) Received: from jason.cygnus.com (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id d70-20020a376849000000b007467a4d8691sm3290197qkc.47.2023.04.03.20.22.56 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 03 Apr 2023 20:22:57 -0700 (PDT) To: gcc-patches@gcc.gnu.org Subject: [pushed] c++: friend template matching [PR107484] Date: Mon, 3 Apr 2023 23:22:48 -0400 Message-Id: <20230404032248.2722677-1-jason@redhat.com> X-Mailer: git-send-email 2.31.1 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.6 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, RCVD_IN_MSPIKE_H2, SPF_HELO_NONE, SPF_NONE, TXREP 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" Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- Here friend matching tries to find a matching non-template friend and fails, so we mark the friend as a template specialization to be determined later. Then cplus_decl_attributes tries again to find a matching function and gets confused by DECL_TEMPLATE_INSTANTIATION without DECL_TEMPLATE_INFO. But it doesn't make sense for find_last_decl to be trying to match anything with DECL_USE_TEMPLATE set; those are matched elsewhere. PR c++/107484 gcc/cp/ChangeLog: * decl2.cc (find_last_decl): Return early if DECL_USE_TEMPLATE. gcc/testsuite/ChangeLog: * g++.dg/lookup/friend25.C: New test. --- gcc/cp/decl2.cc | 5 +++++ gcc/testsuite/g++.dg/lookup/friend25.C | 9 +++++++++ 2 files changed, 14 insertions(+) create mode 100644 gcc/testsuite/g++.dg/lookup/friend25.C base-commit: 59b4a555c3f1c3dba376da1c4886a9ea18ad208d diff --git a/gcc/cp/decl2.cc b/gcc/cp/decl2.cc index 2b195e99997..9594be4092c 100644 --- a/gcc/cp/decl2.cc +++ b/gcc/cp/decl2.cc @@ -1613,6 +1613,11 @@ find_last_decl (tree decl) if (tree name = DECL_P (decl) ? DECL_NAME (decl) : NULL_TREE) { + /* Template specializations are matched elsewhere. */ + if (DECL_LANG_SPECIFIC (decl) + && DECL_USE_TEMPLATE (decl)) + return NULL_TREE; + /* Look up the declaration in its scope. */ tree pushed_scope = NULL_TREE; if (tree ctype = DECL_CONTEXT (decl)) diff --git a/gcc/testsuite/g++.dg/lookup/friend25.C b/gcc/testsuite/g++.dg/lookup/friend25.C new file mode 100644 index 00000000000..74cf5dc3431 --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/friend25.C @@ -0,0 +1,9 @@ +// PR c++/107484 + +namespace qualified_friend_no_match { + void f(int); + template void f(T*); + struct X { + friend void qualified_friend_no_match::f(double); // { dg-error "does not match any template" } + }; +}