From patchwork Thu Sep 19 23:53:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1987598 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.a=rsa-sha256 header.s=20230601 header.b=MWeMMWun; dkim-atps=neutral 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=server2.sourceware.org; envelope-from=gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org; receiver=patchwork.ozlabs.org) Received: from server2.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 (secp384r1) server-digest SHA384) (No client certificate requested) by legolas.ozlabs.org (Postfix) with ESMTPS id 4X8sn65yfTz1y2J for ; Fri, 20 Sep 2024 09:54:18 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 770B33858C39 for ; Thu, 19 Sep 2024 23:54:16 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x436.google.com (mail-pf1-x436.google.com [IPv6:2607:f8b0:4864:20::436]) by sourceware.org (Postfix) with ESMTPS id EFA8A3858D29 for ; Thu, 19 Sep 2024 23:53:52 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org EFA8A3858D29 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=gmail.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org EFA8A3858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::436 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726790035; cv=none; b=beq4gLgV6egal21HtM8DylHJqjh0ESH9GZn2FE9SX5Qs8sFMTKMg0YwhmtzGtIsF8T9oBhYKgEGaGiZOXOvjbYwZ76c2TuzG5kR0oCF7XhctpNWqf+Z0K/dx1K3g3nSZj+NIv6nfSv17c5Wuq+30fHxX3QNIpbNPKAzOWCBi7Wc= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726790035; c=relaxed/simple; bh=gGBwiNWL6FecRiQsHl/P8iBPpDnX41NNBddEDi+x0zc=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=Wkqd5AbBhbOGE4ycz9D0bIs9jTZBBhjET8bC4Md46+OOr1tpc4obSD1CGg4UGPcJoGOECx5l6BfaQwhuuNw76HdJOa0Hk1gguG2d5Nt8mv9K8PJChBcfMWaTSYUd67eyq1vbIayojBEyM7Z4Nx0ownzE5IW0quTWpuxuH0GFOdo= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x436.google.com with SMTP id d2e1a72fcca58-718e0421143so252206b3a.0 for ; Thu, 19 Sep 2024 16:53:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726790032; x=1727394832; darn=gcc.gnu.org; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=lg9fEaHqCiHoaF7gbo5+ChlMy9eEcjO2JsJfFSDb6LA=; b=MWeMMWunn3EX9yCVh8aVa0LiycuBnwyYHa3ATAd3nD/f4fGAtBMNvFvvvFxUGYPxSM 7Za8yqHyXyWYMcDELvPsJvUzcSzAgaqs6uz1r/b9fUt89ZKoGsuXoFnqSZtzTsBFyE/V CL2ZaIc//jFDUaqoMJWCvwbVV1nQqZltYmkSp7ViCMxyUrTJqHBPZMTpKFc16kkDsPRd +Nr7sAN9xzsVg0EW3GIHkEdPbG2UlAmhM/RtY02o1IBPq8fcOcb2QMyBxd8H7hpyJRWJ 03i1/x87YB6lBjKd+SM6vT5plC1RlHeQq8sjzIU6lrsmQVRG16ticktytDFcMIsodQbN bqBg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726790032; x=1727394832; h=content-disposition:mime-version:subject:cc:to:from:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=lg9fEaHqCiHoaF7gbo5+ChlMy9eEcjO2JsJfFSDb6LA=; b=ZFr/MTYndQEeq+QmNTz8vj/U+dNVw/4wHzd6Jk1JUVRPg3MDsPtrzPNvKCBwkDRxp2 PS3gRuA5KkncVywFBTbZv3v5gq5N8BqlPujnHDgVsOqogWuuKGExkfTg+tKQchz7UyMM mlreh/CUOgtQ6wNuREXOM7dPxWbWtT3JcgAQi3JqKlwA6DRgqLtVgTEKPO7c9ICvWkqC ssbYqhCtT+4xnPcklIQovM+Gk1D1zMmO03OgU+wqwJtsw7XCcyDJRW1/d5GFQ//6eGXH 10vtXpC5GNfP3SrUMrOBVLE0SJqdJbdlDNjMvCIzTs64QXCkWAMYhcxK5PTK/YOt/lDt lS5g== X-Gm-Message-State: AOJu0YyiFPaiMFMyGe8CoYT62CwPkeqi399PH8qid2JqMJQM8V2LASxR 8E4Oz8psVGq8oyK6Q5LVTN9DndzBYY3R6pj7YAofRGlo6IzQc0o7uWVdMA== X-Google-Smtp-Source: AGHT+IEMvJkxm0YCPUa2XMll15WbR4pyJbpo3YncqzYu16QlBMHjpwVNqT+1MDd/f5V/3KnsoWZhUQ== X-Received: by 2002:a05:6a00:850:b0:714:2051:89ea with SMTP id d2e1a72fcca58-7199c9390f1mr582048b3a.1.1726790031696; Thu, 19 Sep 2024 16:53:51 -0700 (PDT) Received: from Thaum. (163-47-68-2.ipv4.originbroadband.com.au. [163.47.68.2]) by smtp.gmail.com with ESMTPSA id d2e1a72fcca58-71944b7b15fsm8788652b3a.133.2024.09.19.16.53.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 16:53:51 -0700 (PDT) Message-ID: <66ecb98f.050a0220.2efcb2.522d@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 20 Sep 2024 09:53:46 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Marek Polacek Subject: [PATCH 1/2] c++: Don't strip USING_DECLs when updating local bindings [PR116748] MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-11.8 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, FREEMAIL_FROM, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, SPF_HELO_NONE, SPF_PASS, 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.30 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: gcc-patches-bounces~incoming=patchwork.ozlabs.org@gcc.gnu.org Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? Alternatively I could solve this the other way around (have a new 'old_target = strip_using_decl (old)' and replace all usages of 'old' except the usages in this patch); this is more churn but probably better matches how other functions are structured. -- >8 -- Currently update_binding strips USING_DECLs too eagerly, leading to ICEs in pop_local_decl as it can't find the decl it's popping in the binding list. Let's rather try to keep the original USING_DECL around. This also means that using59.C can point to the location of the using-decl rather than the underlying object directly; this is in the direction required to fix PR c++/106851 (though more work is needed to emit properly helpful diagnostics here). PR c++/116748 gcc/cp/ChangeLog: * name-lookup.cc (update_binding): Maintain USING_DECLs in the binding slots. gcc/testsuite/ChangeLog: * g++.dg/lookup/using59.C: Update location. * g++.dg/lookup/using69.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/name-lookup.cc | 12 +++++++----- gcc/testsuite/g++.dg/lookup/using59.C | 4 ++-- gcc/testsuite/g++.dg/lookup/using69.C | 10 ++++++++++ 3 files changed, 19 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/lookup/using69.C diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index c7a693e02d5..94b031e6be2 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -3005,6 +3005,8 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, if (old == error_mark_node) old = NULL_TREE; + + tree old_bval = old; old = strip_using_decl (old); if (DECL_IMPLICIT_TYPEDEF_P (decl)) @@ -3021,7 +3023,7 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, gcc_checking_assert (!to_type); hide_type = hiding; to_type = decl; - to_val = old; + to_val = old_bval; } else hide_value = hiding; @@ -3034,7 +3036,7 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, /* OLD is an implicit typedef. Move it to to_type. */ gcc_checking_assert (!to_type); - to_type = old; + to_type = old_bval; hide_type = hide_value; old = NULL_TREE; hide_value = false; @@ -3093,7 +3095,7 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, { if (same_type_p (TREE_TYPE (old), TREE_TYPE (decl))) /* Two type decls to the same type. Do nothing. */ - return old; + return old_bval; else goto conflict; } @@ -3106,7 +3108,7 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, /* The new one must be an alias at this point. */ gcc_assert (DECL_NAMESPACE_ALIAS (decl)); - return old; + return old_bval; } else if (TREE_CODE (old) == VAR_DECL) { @@ -3121,7 +3123,7 @@ update_binding (cp_binding_level *level, cxx_binding *binding, tree *slot, else { conflict: - diagnose_name_conflict (decl, old); + diagnose_name_conflict (decl, old_bval); to_val = NULL_TREE; } } diff --git a/gcc/testsuite/g++.dg/lookup/using59.C b/gcc/testsuite/g++.dg/lookup/using59.C index 3c3a73c28d5..b7ec325d234 100644 --- a/gcc/testsuite/g++.dg/lookup/using59.C +++ b/gcc/testsuite/g++.dg/lookup/using59.C @@ -1,10 +1,10 @@ namespace Y { - extern int I; // { dg-message "previous declaration" } + extern int I; } -using Y::I; +using Y::I; // { dg-message "previous declaration" } extern int I; // { dg-error "conflicts with a previous" } extern int J; diff --git a/gcc/testsuite/g++.dg/lookup/using69.C b/gcc/testsuite/g++.dg/lookup/using69.C new file mode 100644 index 00000000000..7d52b73b9ce --- /dev/null +++ b/gcc/testsuite/g++.dg/lookup/using69.C @@ -0,0 +1,10 @@ +// PR c++/116748 + +namespace ns { + struct empty; +} + +void foo() { + using ns::empty; + int empty; +}