From patchwork Tue Sep 22 16:05:13 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1369109 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=2620:52:3:1:0:246e:9693:128c; helo=sourceware.org; envelope-from=gcc-patches-bounces@gcc.gnu.org; receiver=) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20161025 header.b=P6ZtIoyq; 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 RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 4BwmNy3xwsz9sRf for ; Wed, 23 Sep 2020 02:05:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 05B23388C020; Tue, 22 Sep 2020 16:05:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x829.google.com (mail-qt1-x829.google.com [IPv6:2607:f8b0:4864:20::829]) by sourceware.org (Postfix) with ESMTPS id CC8E4388C020 for ; Tue, 22 Sep 2020 16:05:16 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org CC8E4388C020 Authentication-Results: sourceware.org; dmarc=none (p=none dis=none) header.from=acm.org Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=nathanmsidwell@gmail.com Received: by mail-qt1-x829.google.com with SMTP id r8so15959553qtp.13 for ; Tue, 22 Sep 2020 09:05:16 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=sender:to:from:subject:message-id:date:user-agent:mime-version :content-language; bh=TcccBLZHdtF446Z27/UKp1ptVfwnxF94vCdsqjFEu0A=; b=P6ZtIoyqPVcg2px0qwQGWGtF4H6PcBZdaJIl5tq5U1fEpms8nnlNVYqlDYosTmUjQg DN6LmoM22tEVohYorXrAwiGRpw5+3IT9S0toU4PpnKAFwZiuwm5L+QjVd9GFirwBamqC UIogrQnB3AdHXdEJWMqUCqzZOsv/VgGiD8Cy1DXQtE0S9IGELMTt/zt7gMxlt1iviYyv tssJeln3ayfhefhRS9AxThZ+NOg5C0M09k1t1TcOmUP1V/YnXdaVNqz0Ma4C4InM1i1i lai58zcDGUkXCJ61Voqu0/KPYgm49w9ucRFXkpEPpidZ0JjKSltBX8J4icjlprBPnft2 A70g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:to:from:subject:message-id:date :user-agent:mime-version:content-language; bh=TcccBLZHdtF446Z27/UKp1ptVfwnxF94vCdsqjFEu0A=; b=A/pf/nn8mGDAyX6QU5zEa22HzubVMgVcjPnYNw03WbE5AzilVy4gPuBl9T7OUHcl3R 12pMNGSQwesEWLhDxmtqVsrNnsB/dX+R4wbNCVoJ88LhEptbN7PFd8DkVEnyxH0oM5QP iXhIUVsgT5bmB0Nll62tqyxADn2rUFcpgvzWy3e2r7nbE8iKXZ06ZPWViiL8c8TF2MUp YBsxv4eUcnLaqAUBiA3p7l63usxbExEXEDD/fb2tzcb74BT8b2AQOYL71RESjLfh+4ho PETTHCJRLrP9mmHlp1y2XMlr7uUlGi3gWeoEZY7nk7j1rdZ0odeqbdr6g3dabpTEFKVx Qkrw== X-Gm-Message-State: AOAM530MqYuJaTxfapRjdT/iikIVdlPvAFrn3Nybc9MbPH1CJ2cHBOUi /71tVI71wSUgTTWAoJNxRdTTStn6bbc= X-Google-Smtp-Source: ABdhPJx10DIr58tjiAuZiPZknT/PduoUor4eDMguViHWsbTjMh9O4sHdGyiPJiLhZoxPxaj3w3HPZA== X-Received: by 2002:ac8:47cf:: with SMTP id d15mr5342890qtr.197.1600790716178; Tue, 22 Sep 2020 09:05:16 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:e142:cf37:14c0:c486? ([2620:10d:c091:480::1:a2b7]) by smtp.googlemail.com with ESMTPSA id w94sm12935227qte.93.2020.09.22.09.05.14 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Sep 2020 09:05:14 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: fix injected friend of template class Message-ID: <56808bf8-cd88-7efe-64b7-235a8ceb08c3@acm.org> Date: Tue, 22 Sep 2020 12:05:13 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101 Thunderbird/68.5.0 MIME-Version: 1.0 Content-Language: en-US X-Spam-Status: No, score=-9.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_EF, FREEMAIL_FORGED_FROMDOMAIN, FREEMAIL_FROM, GIT_PATCH_0, HEADER_FROM_DIFFERENT_DOMAINS, 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: , Errors-To: gcc-patches-bounces@gcc.gnu.org Sender: "Gcc-patches" In working on fixing hiddenness, I discovered some suspicious code in template instantiation. I suspect it dates from when we didn't do the hidden friend injection thing at all. The xreftag finds the same class, but makes it visible to name lookup. Which is wrong. hurrah, fixing a bug by deleting code! gcc/cp/ * pt.c (instantiate_class_template_1): Do not repush and unhide injected friend. gcc/testsuite/ * g++.old-deja/g++.pt/friend34.C: Check injected friend is still invisible. pushed to trunk nathan diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 97d0c245f7e..44ca14afc4e 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -12030,25 +12030,6 @@ instantiate_class_template_1 (tree type) adjust_processing_template_decl = true; --processing_template_decl; } - else if (TREE_CODE (friend_type) != BOUND_TEMPLATE_TEMPLATE_PARM - && !CLASSTYPE_USE_TEMPLATE (friend_type) - && TYPE_HIDDEN_P (friend_type)) - { - /* friend class C; - - where C hasn't been declared yet. Let's lookup name - from namespace scope directly, bypassing any name that - come from dependent base class. */ - tree ns = decl_namespace_context (TYPE_MAIN_DECL (friend_type)); - - /* The call to xref_tag_from_type does injection for friend - classes. */ - push_nested_namespace (ns); - friend_type = - xref_tag_from_type (friend_type, NULL_TREE, - /*tag_scope=*/ts_current); - pop_nested_namespace (ns); - } else if (uses_template_parms (friend_type)) /* friend class C; */ friend_type = tsubst (friend_type, args, diff --git i/gcc/testsuite/g++.old-deja/g++.pt/friend34.C w/gcc/testsuite/g++.old-deja/g++.pt/friend34.C index 5e80ab98b2e..dcd6df0ce55 100644 --- i/gcc/testsuite/g++.old-deja/g++.pt/friend34.C +++ w/gcc/testsuite/g++.old-deja/g++.pt/friend34.C @@ -6,9 +6,12 @@ template class bar { public: - friend class foo; // this is not bar::foo, it forward-declares ::foo + friend class foo; // this is not bar::foo, it injects hidden ::foo class foo {}; bar() { foo(); } // but this should refer to bar::foo }; bar<> baz; + +// We still have not made foo visible. +foo *b; // { dg-error "does not name a type" }