From patchwork Wed Sep 30 13:45:17 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1374367 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=SwYRVntF; 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 4C1cw11mPhz9sSG for ; Wed, 30 Sep 2020 23:45:36 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id AEC1F398796C; Wed, 30 Sep 2020 13:45:33 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qt1-x82c.google.com (mail-qt1-x82c.google.com [IPv6:2607:f8b0:4864:20::82c]) by sourceware.org (Postfix) with ESMTPS id 5B7BB3987938 for ; Wed, 30 Sep 2020 13:45:21 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 5B7BB3987938 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-x82c.google.com with SMTP id y11so1166151qtn.9 for ; Wed, 30 Sep 2020 06:45:21 -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=c6ZKUo4eJK3R8Mhk2PpZMD/98tTKcRs9ZlZYF4x8ihY=; b=SwYRVntFu/ldzMzI9ONaXvCaGGlELd5687f6znrt8BF004UINGoR4xbOuVMHsCIgAe 4Pg9zVHpYmapelLGewVl1TeVh9UBKFJE26at9s6pZYJiOF2u625G8heXqFC3JqrN7QsC Lt0NCP53wa72+srlFlBCnfLKIZiEotNWvSpLIFOdlMmKJyVAgnLgCqn2XLC7hDMn1ZdO p3pdyfYXejprMMgF3qOsMJt0DbSYTUA2cw/F6mQ3Oea70HkhqYgcowrCJ1+o2ZhcQaBx Hzm0gWh3vsvqasWgxtfy8TT1ur+6Ees0GX3bRo7Kk86wnn9t98/E43TSdxMVWfpwne/h UI2w== 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=c6ZKUo4eJK3R8Mhk2PpZMD/98tTKcRs9ZlZYF4x8ihY=; b=SxVOcMKyDN1GiAtkyZLNIXgm7Q2oa3hd7dWxnh55ENSG0GHA6/8BwRE+7f8CXcyctv 9rB+nJbEfHn3/a2IpdTwN+rAobe8GTwjikVzcOUoqLLjvDs0Wp5VxFTjwUyBosVpyLzq x7amx5LeCo/dX/ijlGeAVSYHvfwSXSdXQR+H4nQ+UFLpwHVCQ3/Dt0rXRaEK+hHzki6k hq7zYjUwtMEDcFxYm02tPhnIYD0OH163T4FJC9ppb00YFxxnefMOAL6EsJ/9vWLJdpyf jroegsVcEoA6FTO3+PpNEE3o/xr/jZUmy4sbIeGILpEhJH/TJIaWJm4AXGq04SGxbOw0 e/8A== X-Gm-Message-State: AOAM5328YnVxZ/wIzN/d++536j9AClpOjIrWVrR1x31+Jln6fm+nSXKl qQYnbvD5oqj6X5tG+0dwHT8= X-Google-Smtp-Source: ABdhPJw/Yu9R3pftMv3jbEJcWDPZ6eIeyYhuFxQbxKqtYYp9pl9833fuO6bj0d39i56d2tjM68E34g== X-Received: by 2002:ac8:5d0d:: with SMTP id f13mr2264783qtx.87.1601473520425; Wed, 30 Sep 2020 06:45:20 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:2109:54ca:fda0:3fff? ([2620:10d:c091:480::1:dd24]) by smtp.googlemail.com with ESMTPSA id w94sm2365556qte.93.2020.09.30.06.45.18 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 30 Sep 2020 06:45:19 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Kill DECL_HIDDEN_FRIEND_P Message-ID: Date: Wed, 30 Sep 2020 09:45:17 -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=-10.0 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" Now hiddenness is managed by name-lookup, we no longer need DECL_HIDDEN_FRIEND_P. This removes it. Mainly by deleting its bookkeeping, but there are a couple of uses 1) two name lookups look at it to see if they found a hidden thing. In one we have the OVERLOAD, so can record OVL_HIDDEN_P. In the other we're repeating a lookup that failed, but asking for hidden things -- so if that succeeds we know the thing was hidden. (FWIW CWG recently discussed whether template specializations and instantiations should see such hidden templates anyway, there is compiler divergence.) 2) We had a confusing setting of KOENIG_P when building a non-dependent call. We don't repeat that lookup at instantiation time anyway. gcc/cp/ * cp-tree.h (struct lang_decl_fn): Remove hidden_friend_p. (DECL_HIDDEN_FRIEND_P): Delete. * call.c (add_function_candidate): Drop assert about anticipated decl. (build_new_op_1): Drop koenig lookup flagging for hidden friend. * decl.c (duplicate_decls): Drop HIDDEN_FRIEND_P updating. * name-lookup.c (do_pushdecl): Likewise. (set_decl_namespace): Discover hiddenness from OVL_HIDDEN_P. * pt.c (check_explicit_specialization): Record found_hidden explicitly. pushing to trunk nathan diff --git i/gcc/cp/call.c w/gcc/cp/call.c index 5606389f4bd..da013e17e14 100644 --- i/gcc/cp/call.c +++ w/gcc/cp/call.c @@ -2220,11 +2220,6 @@ add_function_candidate (struct z_candidate **candidates, int viable = 1; struct rejection_reason *reason = NULL; - /* At this point we should not see any functions which haven't been - explicitly declared, except for friend functions which will have - been found using argument dependent lookup. */ - gcc_assert (!DECL_ANTICIPATED (fn) || DECL_HIDDEN_FRIEND_P (fn)); - /* The `this', `in_chrg' and VTT arguments to constructors are not considered in overload resolution. */ if (DECL_CONSTRUCTOR_P (fn)) @@ -6344,11 +6339,6 @@ build_new_op_1 (const op_location_t &loc, enum tree_code code, int flags, tree call = extract_call_expr (result); CALL_EXPR_OPERATOR_SYNTAX (call) = true; - if (processing_template_decl && DECL_HIDDEN_FRIEND_P (cand->fn)) - /* This prevents build_new_function_call from discarding this - function during instantiation of the enclosing template. */ - KOENIG_LOOKUP_P (call) = 1; - /* Specify evaluation order as per P0145R2. */ CALL_EXPR_ORDERED_ARGS (call) = false; switch (op_is_ordered (code)) diff --git i/gcc/cp/cp-tree.h w/gcc/cp/cp-tree.h index a25934e3263..762a3519b7c 100644 --- i/gcc/cp/cp-tree.h +++ w/gcc/cp/cp-tree.h @@ -2720,14 +2720,13 @@ struct GTY(()) lang_decl_fn { unsigned thunk_p : 1; unsigned this_thunk_p : 1; - unsigned hidden_friend_p : 1; unsigned omp_declare_reduction_p : 1; unsigned has_dependent_explicit_spec_p : 1; unsigned immediate_fn_p : 1; unsigned maybe_deleted : 1; unsigned coroutine_p : 1; - unsigned spare : 9; + unsigned spare : 10; /* 32-bits padding on 64-bit host. */ @@ -4067,12 +4066,6 @@ more_aggr_init_expr_args_p (const aggr_init_expr_arg_iterator *iter) #define DECL_OMP_PRIVATIZED_MEMBER(NODE) \ (DECL_LANG_SPECIFIC (VAR_DECL_CHECK (NODE))->u.base.anticipated_p) -/* Nonzero if NODE is a FUNCTION_DECL which was declared as a friend - within a class but has not been declared in the surrounding scope. - The function is invisible except via argument dependent lookup. */ -#define DECL_HIDDEN_FRIEND_P(NODE) \ - (LANG_DECL_FN_CHECK (DECL_COMMON_CHECK (NODE))->hidden_friend_p) - /* Nonzero if NODE is an artificial FUNCTION_DECL for #pragma omp declare reduction. */ #define DECL_OMP_DECLARE_REDUCTION_P(NODE) \ diff --git i/gcc/cp/decl.c w/gcc/cp/decl.c index 617b96e02e4..14742c115ad 100644 --- i/gcc/cp/decl.c +++ w/gcc/cp/decl.c @@ -2141,10 +2141,7 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) olddecl_hidden_friend = olddecl_friend && was_hidden; hidden_friend = olddecl_hidden_friend && hiding; if (!hidden_friend) - { - DECL_ANTICIPATED (olddecl) = 0; - DECL_HIDDEN_FRIEND_P (olddecl) = 0; - } + DECL_ANTICIPATED (olddecl) = false; } if (TREE_CODE (newdecl) == TEMPLATE_DECL) @@ -2892,12 +2889,9 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) DECL_UID (olddecl) = olddecl_uid; if (olddecl_friend) - DECL_FRIEND_P (olddecl) = 1; + DECL_FRIEND_P (olddecl) = true; if (hidden_friend) - { - DECL_ANTICIPATED (olddecl) = 1; - DECL_HIDDEN_FRIEND_P (olddecl) = 1; - } + DECL_ANTICIPATED (olddecl) = true; /* NEWDECL contains the merged attribute lists. Update OLDDECL to be the same. */ diff --git i/gcc/cp/name-lookup.c w/gcc/cp/name-lookup.c index bc60d343f7e..8cd6fe38271 100644 --- i/gcc/cp/name-lookup.c +++ w/gcc/cp/name-lookup.c @@ -3172,7 +3172,7 @@ do_pushdecl (tree decl, bool hiding) return error_mark_node; } /* Hide it from ordinary lookup. */ - DECL_ANTICIPATED (decl) = DECL_HIDDEN_FRIEND_P (decl) = true; + DECL_ANTICIPATED (decl) = true; } } @@ -4924,8 +4924,15 @@ set_decl_namespace (tree decl, tree scope, bool friendp) /* Since decl is a function, old should contain a function decl. */ if (!OVL_P (old)) - goto not_found; + { + not_found: + /* It didn't work, go back to the explicit scope. */ + DECL_CONTEXT (decl) = FROB_CONTEXT (scope); + error ("%qD should have been declared inside %qD", decl, scope); + return; + } + /* We handle these in check_explicit_instantiation_namespace. */ if (processing_explicit_instantiation) return; @@ -4935,13 +4942,14 @@ set_decl_namespace (tree decl, tree scope, bool friendp) match. But, we'll check later, when we construct the template. */ return; + /* Instantiations or specializations of templates may be declared as friends in any namespace. */ if (friendp && DECL_USE_TEMPLATE (decl)) return; - tree found; - found = NULL_TREE; + tree found = NULL_TREE; + bool hidden_p = false; for (lkp_iterator iter (old); iter; ++iter) { @@ -4957,17 +4965,20 @@ set_decl_namespace (tree decl, tree scope, bool friendp) { if (found) { - /* We found more than one matching declaration. */ + /* We found more than one matching declaration. This + can happen if we have two inline namespace children, + each containing a suitable declaration. */ DECL_CONTEXT (decl) = FROB_CONTEXT (scope); goto ambiguous; } found = ofn; + hidden_p = iter.hidden_p (); } } if (found) { - if (DECL_HIDDEN_FRIEND_P (found)) + if (hidden_p) { pedwarn (DECL_SOURCE_LOCATION (decl), 0, "%qD has not been declared within %qD", decl, scope); @@ -4978,10 +4989,7 @@ set_decl_namespace (tree decl, tree scope, bool friendp) goto found; } - not_found: - /* It didn't work, go back to the explicit scope. */ - DECL_CONTEXT (decl) = FROB_CONTEXT (scope); - error ("%qD should have been declared inside %qD", decl, scope); + goto not_found; } /* Return the namespace where the current declaration is declared. */ diff --git i/gcc/cp/pt.c w/gcc/cp/pt.c index a09633751ca..652b4583b35 100644 --- i/gcc/cp/pt.c +++ w/gcc/cp/pt.c @@ -2988,6 +2988,7 @@ check_explicit_specialization (tree declarator, tree tmpl = NULL_TREE; tree targs = NULL_TREE; bool was_template_id = (TREE_CODE (declarator) == TEMPLATE_ID_EXPR); + bool found_hidden = false; /* Make sure that the declarator is a TEMPLATE_ID_EXPR. */ if (!was_template_id) @@ -3008,12 +3009,15 @@ check_explicit_specialization (tree declarator, fns = lookup_qualified_name (CP_DECL_CONTEXT (decl), dname, LOOK_want::NORMAL, true); if (fns == error_mark_node) - /* If lookup fails, look for a friend declaration so we can - give a better diagnostic. */ - fns = (lookup_qualified_name - (CP_DECL_CONTEXT (decl), dname, - LOOK_want::NORMAL | LOOK_want::HIDDEN_FRIEND, - /*complain*/true)); + { + /* If lookup fails, look for a friend declaration so we can + give a better diagnostic. */ + fns = (lookup_qualified_name + (CP_DECL_CONTEXT (decl), dname, + LOOK_want::NORMAL | LOOK_want::HIDDEN_FRIEND, + /*complain*/true)); + found_hidden = true; + } if (fns == error_mark_node || !is_overloaded_fn (fns)) { @@ -3122,8 +3126,7 @@ check_explicit_specialization (tree declarator, return error_mark_node; else { - if (TREE_CODE (decl) == FUNCTION_DECL - && DECL_HIDDEN_FRIEND_P (tmpl)) + if (found_hidden && TREE_CODE (decl) == FUNCTION_DECL) { auto_diagnostic_group d; if (pedwarn (DECL_SOURCE_LOCATION (decl), 0, @@ -3132,8 +3135,9 @@ check_explicit_specialization (tree declarator, inform (DECL_SOURCE_LOCATION (tmpl), "friend declaration here"); } - else if (!ctype && !is_friend - && CP_DECL_CONTEXT (decl) == current_namespace) + + if (!ctype && !is_friend + && CP_DECL_CONTEXT (decl) == current_namespace) check_unqualified_spec_or_inst (tmpl, DECL_SOURCE_LOCATION (decl)); tree gen_tmpl = most_general_template (tmpl);