From patchwork Wed Oct 14 12:09:19 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 1382092 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=OeH1NAtt; 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 4CBB6f2RZvz9sTs for ; Wed, 14 Oct 2020 23:09:28 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 2A22E3854825; Wed, 14 Oct 2020 12:09:25 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-qk1-x72a.google.com (mail-qk1-x72a.google.com [IPv6:2607:f8b0:4864:20::72a]) by sourceware.org (Postfix) with ESMTPS id 99DDD3857C4F for ; Wed, 14 Oct 2020 12:09:22 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.3.2 sourceware.org 99DDD3857C4F 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-qk1-x72a.google.com with SMTP id s14so865718qkg.11 for ; Wed, 14 Oct 2020 05:09:22 -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=U5LWIuKiQAuPIbrtD3eE++h07jncDWq9HDQP9lzPq1M=; b=OeH1NAttT3/DTEqeYeHeUlk9VrmZdJphcUKypLGm1Q22m4W4wSXL5bg/FiyyxXKCus dAWoM3i9qfIsV/d/h/MekLYBvnYORlf03fSsrnBdjvH/zDNkM+fQHZUlLuA4IWF7hqYP Fkyf9WHUeGIEHmB1o8XFawr31RVFO+ni3NSEz57+c6iD34J+dMs1NTytFjph6yJ9vViJ 5vPsOkFnROZCnJjbWiVLJUQ7zXK2cd56Zu7dswA16Mq4eoQ6h5zSNin+7AmWl3g2mAr/ mKNtogh5WZRllSczd5s83x4PeoxAmw1RMv5OWoqtTEHXS/3bbHf7pZqBHkhnVAtZFhn6 acDw== 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=U5LWIuKiQAuPIbrtD3eE++h07jncDWq9HDQP9lzPq1M=; b=gYmJpbqAHDp3hLZYFDV+7rB9hqQquu2r2xErDf/HRIaeBWCp8EG5hGi95DXu2Ay2cs +oDvKze6o18L7cyaU7NeMY1NgjP9F4d/ZNVv4SAko6uMMHTydTbZr1n+JBTMq+zs1xT6 gjLLdfZFPilR4C7eEK4Fficnd4dLFMfSUasjqIA3qqI6CYSN20aT4cqq2sPbDXqA4eGr XcQxV4z6jeDFE3n01nRy8j112IsIK/TQ9PAhrb7BEnOUJXgGDGoxpuTcQeCi40uFlUhw Gp582HtXCTtb0LK0yUcySn03t9RjU2sCK7RT19NySwDFV0oOtPm9LdVdIX7pXBn7RcHW 9dlA== X-Gm-Message-State: AOAM531MFOOSR3oN+gK7GdIoOuQRzJK48Z+SBgiiDwuqy8tXm9t8uacV tqBe2xSUz+m28tj5knN8e3Y= X-Google-Smtp-Source: ABdhPJxljv7r5+ufLIHta6lkpLFiB9D/amBW6Xf7biBrZ0TH6VyJ7A9tI1mVNGjkD/xGcgOKzw/qlA== X-Received: by 2002:a05:620a:2107:: with SMTP id l7mr4632269qkl.249.1602677361995; Wed, 14 Oct 2020 05:09:21 -0700 (PDT) Received: from ?IPv6:2620:10d:c0a8:1102:7116:6dab:ada8:cf31? ([2620:10d:c091:480::1:68cb]) by smtp.googlemail.com with ESMTPSA id v39sm1218263qtk.81.2020.10.14.05.09.20 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Wed, 14 Oct 2020 05:09:20 -0700 (PDT) To: GCC Patches From: Nathan Sidwell Subject: c++: Instantiation with local extern [PR97395] Message-ID: <82cfeffb-14b4-6960-035c-56a6d4dee435@acm.org> Date: Wed, 14 Oct 2020 08:09:19 -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=-11.1 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" It turns out that pushdecl_with_scope has somewhat strange behaviour, which probably made more sense way back. Unfortunately making it somewhat saner turned into a rathole. Instead use a push_nested_namespace around pushing the alias -- this is similar to some of the friend handling we already have. gcc/cp/ * name-lookup.c (push_local_extern_decl_alias): Push into alias's namespace and use pushdecl. (do_pushdecl_with_scope): Clarify behaviour. gcc/testsuite/ * g++.dg/lookup/extern-redecl2.C: New. pushing to trunk nathan diff --git c/gcc/cp/name-lookup.c w/gcc/cp/name-lookup.c index e3f3712b1f0..5dcaab4d1df 100644 --- c/gcc/cp/name-lookup.c +++ w/gcc/cp/name-lookup.c @@ -38,7 +38,7 @@ along with GCC; see the file COPYING3. If not see static cxx_binding *cxx_binding_make (tree value, tree type); static cp_binding_level *innermost_nonclass_level (void); -static tree do_pushdecl_with_scope (tree x, cp_binding_level *, bool hiding); +static tree do_pushdecl (tree decl, bool hiding); static void set_identifier_type_value_with_scope (tree id, tree decl, cp_binding_level *b); static name_hint maybe_suggest_missing_std_header (location_t location, @@ -2975,8 +2975,9 @@ push_local_extern_decl_alias (tree decl) /* Expected default linkage is from the namespace. */ TREE_PUBLIC (alias) = TREE_PUBLIC (ns); - alias = do_pushdecl_with_scope (alias, NAMESPACE_LEVEL (ns), - /* hiding= */true); + push_nested_namespace (ns); + alias = do_pushdecl (alias, /* hiding= */true); + pop_nested_namespace (ns); } } @@ -3848,10 +3849,17 @@ constructor_name_p (tree name, tree type) /* Same as pushdecl, but define X in binding-level LEVEL. We rely on the caller to set DECL_CONTEXT properly. - Note that this must only be used when X will be the new innermost - binding for its name, as we tack it onto the front of IDENTIFIER_BINDING - without checking to see if the current IDENTIFIER_BINDING comes from a - closer binding level than LEVEL. */ + Warning: For class and block-scope this must only be used when X + will be the new innermost binding for its name, as we tack it onto + the front of IDENTIFIER_BINDING without checking to see if the + current IDENTIFIER_BINDING comes from a closer binding level than + LEVEL. + + Warning: For namespace scope, this will look in LEVEL for an + existing binding to match, but if not found will push the decl into + CURRENT_NAMESPACE. Use push_nested_namespace/pushdecl/ + pop_nested_namespace if you really need to push it into a foreign + namespace. */ static tree do_pushdecl_with_scope (tree x, cp_binding_level *level, bool hiding = false) diff --git c/gcc/testsuite/g++.dg/lookup/extern-redecl2.C w/gcc/testsuite/g++.dg/lookup/extern-redecl2.C new file mode 100644 index 00000000000..9c5caa6b677 --- /dev/null +++ w/gcc/testsuite/g++.dg/lookup/extern-redecl2.C @@ -0,0 +1,18 @@ +// PR 97395 +// ICE injecting hidden decl in wrong namespace + +namespace pr { + template + void + kp () + { + extern WW hz; + } + + void + n5 () + { + kp (); + kp (); + } +}