From patchwork Thu Dec 3 19:17:07 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1410578 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=8.43.85.97; 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=U4N5IpJx; dkim-atps=neutral Received: from sourceware.org (server2.sourceware.org [8.43.85.97]) (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 4Cn5F862d9z9sSf for ; Fri, 4 Dec 2020 06:17:14 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id E56F2386EC78; Thu, 3 Dec 2020 19:17:12 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qv1-xf36.google.com (mail-qv1-xf36.google.com [IPv6:2607:f8b0:4864:20::f36]) by sourceware.org (Postfix) with ESMTPS id 7336B3857003 for ; Thu, 3 Dec 2020 19:17:10 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 7336B3857003 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-qv1-xf36.google.com with SMTP id q7so1517292qvt.12 for ; Thu, 03 Dec 2020 11:17:10 -0800 (PST) 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=vvNBKEzONFjMqxWuzD5hDusRgGt/J12pRSQ4ciH2tZI=; b=U4N5IpJxnR8kPQY4ymCzudcOw0EYHOJcreUz4/Yl96f9WeZkpVsQoiNoLVAxRi7Yej guFMKYV2Lj9foYk97D7yMAYL/7Ee/Sfj7Lf1/k3cGfVfkpd8CL4wDR/gseh2vtZWv4qC 1L0BXz0bcaVVTObOAIgCH2eXm2ZbjIJeO3YQ/4NLK+cSTd869IbZ1pcevUcGiL6nvwdV uwMQt5uxK7VFfxKAikhKgcyBEieOuYkous7SlluRYLk929XgboOazUVYJNSHFO/HM3eN V7ZxEPfl+gH1cXvUwlyjByN7AgkmCqj5pkfV6cG31RCBmOgINYLP8dLHjZLIaVc856BY hw0g== 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=vvNBKEzONFjMqxWuzD5hDusRgGt/J12pRSQ4ciH2tZI=; b=J1F8HLsANCvhXnwxfPW8+0+wJQZSoyoW3+YaqmfjcRQ7szYzDCsD0p4KdQwSu6vRU7 2z4GMvlmjaGvsbcBrbTuBacBBpK9P2lVIsHU/dia2FwOixNB1B64Ke5c5uZTJMwJbW0O iD1a9DD08sIARdwbvOYelDmcsx+glBdlHmUXYuCPZj5rNlR3T3lcRl9dpJoWeNXzhLhA Nug6KRpQ9H2lFDKfSICkRkAJExFtZ0Qgin6w0eB6biKXd62wsPipcEXAW/f68nRAf6Gf H36f7oaM2j1PON8jr+JGPFvx19LvI0qTweIXjZDmvIiWyJungVmi6g56PdCcI8Wh1q1g TVnA== X-Gm-Message-State: AOAM530hhey6kxwBy8jW9iomnic7q0RMv3+olJvo6aPXGUfKmdGkjRm8 HtV6G3eaS/1SHucdU+WjEqk= X-Google-Smtp-Source: ABdhPJymld9HhGWL3/Ym8qnnGRNqRuom6WlmC1CbEdjPJnpH8HpECqAxaB67M1XlVWle7M9h1SQxnA== X-Received: by 2002:a05:6214:a8f:: with SMTP id ev15mr639213qvb.20.1607023029828; Thu, 03 Dec 2020 11:17:09 -0800 (PST) Received: from ?IPv6:2620:10d:c0a8:1102:ded:7157:da24:d154? ([2620:10d:c091:480::1:e9f0]) by smtp.googlemail.com with ESMTPSA id d140sm2187682qke.59.2020.12.03.11.17.08 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Dec 2020 11:17:08 -0800 (PST) To: GCC Patches From: Nathan Sidwell Subject: c++: uninstantiated template friends Message-ID: Date: Thu, 3 Dec 2020 14:17:07 -0500 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=-11.4 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" template friends need to be recognized by module streaming and associated with the befriending class. but their context is that of the friend (a namespace or other class). This adds a flag to mark such templates, and uses their DECL_CHAIN to point at the befriender. gcc/cp * cp-tree.h (DECL_UNINSTANTIATED_TEMPLATE_FRIEND): New. * pt.c (push_template_decl): Set it. (tsubst_friend_function): Clear it. pushing to trunk diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index 69f8ed56e62..4db50128443 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -545,6 +545,7 @@ extern GTY(()) tree cp_global_trees[CPTI_MAX]; DECL_ANON_UNION_VAR_P (in a VAR_DECL) DECL_SELF_REFERENCE_P (in a TYPE_DECL) DECL_INVALID_OVERRIDER_P (in a FUNCTION_DECL) + DECL_UNINSTANIATED_TEMPLATE_FRIEND_P (in TEMPLATE_DECL) 5: DECL_INTERFACE_KNOWN. 6: DECL_THIS_STATIC (in VAR_DECL, FUNCTION_DECL or PARM_DECL) DECL_FIELD_IS_BASE (in FIELD_DECL) @@ -3161,6 +3162,13 @@ struct GTY(()) lang_decl { (DECL_LANG_SPECIFIC (FUNCTION_DECL_CHECK (NODE)) \ ->u.base.friend_or_tls) +/* True of a TEMPLATE_DECL that is a template class friend. Such + decls are not pushed until instantiated (as they may depend on + parameters of the befriending class). DECL_CHAIN is the + befriending class. */ +#define DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P(NODE) \ + (DECL_LANG_FLAG_4 (TEMPLATE_DECL_CHECK (NODE))) + /* Nonzero if the thread-local variable was declared with __thread as opposed to thread_local. */ #define DECL_GNU_TLS_P(NODE) \ diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index 3ca28133d94..08931823d57 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -22,7 +22,9 @@ along with GCC; see the file COPYING3. If not see /* Known bugs or deficiencies include: all methods must be provided in header files; can't use a source - file that contains only the method templates and "just win". */ + file that contains only the method templates and "just win". + + Fixed by: C++20 modules. */ #include "config.h" #include "system.h" @@ -6044,6 +6046,14 @@ push_template_decl (tree decl, bool is_friend) tmpl = NULL_TREE; } } + else if (is_friend) + { + /* Record this decl as belonging to the current class. It's + not chained onto anything else. */ + DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (tmpl) = true; + gcc_checking_assert (!DECL_CHAIN (tmpl)); + DECL_CHAIN (tmpl) = current_scope (); + } } else if (tmpl) /* The type may have been completed, or (erroneously) changed. */ @@ -11053,6 +11063,7 @@ tsubst_friend_function (tree decl, tree args) DECL_USE_TEMPLATE (new_friend) = 0; if (TREE_CODE (new_friend) == TEMPLATE_DECL) { + DECL_UNINSTANTIATED_TEMPLATE_FRIEND_P (new_friend) = false; DECL_USE_TEMPLATE (DECL_TEMPLATE_RESULT (new_friend)) = 0; DECL_SAVED_TREE (DECL_TEMPLATE_RESULT (new_friend)) = DECL_SAVED_TREE (DECL_TEMPLATE_RESULT (decl));