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: 97726 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id D118F3858C41 for ; Thu, 19 Sep 2024 23:54:23 +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~patchwork=sourceware.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; +} From patchwork Thu Sep 19 23:56:56 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 97727 Return-Path: X-Original-To: patchwork@sourceware.org Delivered-To: patchwork@sourceware.org Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 0A5283858C52 for ; Thu, 19 Sep 2024 23:57:28 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by sourceware.org (Postfix) with ESMTPS id 61D133858D29 for ; Thu, 19 Sep 2024 23:57:02 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 61D133858D29 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 61D133858D29 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::432 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726790224; cv=none; b=FjXeLfWaBX2y10hwAY3qMRrHXNUE7A0A8ky8ypjtzXJ3JEEnR3Wi3p1MGlrtS1UkuvzJeUWXvwor98HKhldi8UBMeW9K/DqUrEGHTEjJLbrIUA06/aBunFCvf0m9UHY88ZiiVu9R4Xc0bdQ4B5BdUsXg0UyWbG6/q1BXzmQibqU= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1726790224; c=relaxed/simple; bh=P5k10cgB8MAZH6CiOt14Rfsv27GubLav4J3PYNUUxWI=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=j8EcpxYl6rdNvXwMMfPYQdb9M0WEv7vYIJ/tkMnkJD6/EjNK2PWnzWYCY+UlnG+oY+jaHmhMqYNFYltgHnTcvT1ISA372jRF2MHpwF1V+3ywyxU6gi+Pjf366jaXyEwz1vX4tvlzCcBIMjvN2zrZrKfqhdpBeTSKPxNkhFcEhoY= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pf1-x432.google.com with SMTP id d2e1a72fcca58-718e25d8b67so172214b3a.3 for ; Thu, 19 Sep 2024 16:57:02 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1726790221; x=1727395021; darn=gcc.gnu.org; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:from:to:cc:subject:date:message-id:reply-to; bh=zk3NOFQJ80wgxxppCIvFIuMyAigJNOC72kYywJtBLIw=; b=URm/rRv5rvFeLRdAbMv1YaRXsCOoQCepsHzwc/Foq168phmFCBI2JTCGtanU8w+tt3 PHumAO25BTLQKuH/I9RolXICzPJcIsaNol1m3XHx7n0P7BBGy0lhcKPvffXsf/nE8eWt PRJudwpdgNZ6XlSxPY8TUZ/uy/uH5hM3p+ufJlWw4fJ6GJz0K+aqN58R25I+J0DffZqX KJGAA0XA3sS3gPw49AVyUUSLHPCxU2RYqQRSiKEXqzyBzrevWlIUnknD1KVhNdFKlBr6 kFwAxBARYnogGq0NBv8wOc2vS9EkEyq8BwC2T4/b9Kt2AaQSfO1JViO6D/aElm9tsI/R y9lw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1726790221; x=1727395021; h=in-reply-to:content-disposition:mime-version:references:subject:cc :to:from:date:message-id:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=zk3NOFQJ80wgxxppCIvFIuMyAigJNOC72kYywJtBLIw=; b=YxWHiHq0chtto7Bthm0oDuoI7I2+9VAWF8VJN/eggFYGF5aZcCbX51HNV1HyenCbLL xWe6l2SSrBoHeFkVYAep5HMJtv/QRpLuz0zorCRYZwleYE5GO1c+mD++lGzUwHr9uKo1 N7IhRko0uAD0gJxBU2Rbwq03cSIzbhq18vljiJanKg0hU9enUxflTCzqVdfSexTyWQ7T J9OqjIXs4j4sl6uEMj9E3DWGB/NISJpw8C1SUGxnCwUHSpZZ9mFFAmZGBjl4J2g4NFFq 1W1A3K3EudmNjM16YaPEllUXitf9ktuejvzQ9qkT7LlWSxF5wNShjl1MenAhQ8wFOQoN LYIQ== X-Gm-Message-State: AOJu0Yz5BIP+6TFD1/l4ytizxNS4wBnOd33ilxqKfU4pDGY6V3wd7YZv lHKB15+caFlIuXOWMWSsMFbPMwFblHrkC0RF39e4RLmmxn0CIBrjFPgz8w== X-Google-Smtp-Source: AGHT+IHzm9OtoxVSyqC5sYxXfketdSUGe3Hj48Lmbm9tzUcUktWJrusASclpCbnrypjh+a5veRuHCA== X-Received: by 2002:a05:6a00:3d49:b0:710:51cd:ed43 with SMTP id d2e1a72fcca58-7199c973aa1mr570251b3a.1.1726790220916; Thu, 19 Sep 2024 16:57:00 -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-71944b7aeafsm9085469b3a.99.2024.09.19.16.56.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 19 Sep 2024 16:57:00 -0700 (PDT) Message-ID: <66ecba4c.a70a0220.34a92e.63ed@mx.google.com> X-Google-Original-Message-ID: Date: Fri, 20 Sep 2024 09:56:56 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Marek Polacek Subject: [PATCH 2/2] c++: Implement resolution for DR 36 [PR116160] References: <66ecb98f.050a0220.2efcb2.522d@mx.google.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <66ecb98f.050a0220.2efcb2.522d@mx.google.com> X-Spam-Status: No, score=-11.9 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~patchwork=sourceware.org@gcc.gnu.org Noticed how to fix this while working on the other patch. Bootstrapped and regtested on x86_64-pc-linux-gnu, OK for trunk? -- >8 -- This implements part of P1787 to no longer complain about redeclaring an entity via using-decl other than in a class scope. PR c++/116160 gcc/cp/ChangeLog: * name-lookup.cc (supplement_binding): Allow redeclaration via USING_DECL if not in class scope. (do_nonmember_using_decl): Remove function-scope exemption. (push_using_decl_bindings): Remove outdated comment. gcc/testsuite/ChangeLog: * g++.dg/cpp0x/using-enum-3.C: No longer expect an error. * g++.dg/lookup/using53.C: Remove XFAIL. * g++.dg/cpp2a/using-enum-11.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/name-lookup.cc | 12 +++++++----- gcc/testsuite/g++.dg/cpp0x/using-enum-3.C | 2 +- gcc/testsuite/g++.dg/cpp2a/using-enum-11.C | 9 +++++++++ gcc/testsuite/g++.dg/lookup/using53.C | 2 +- 4 files changed, 18 insertions(+), 7 deletions(-) create mode 100644 gcc/testsuite/g++.dg/cpp2a/using-enum-11.C diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 94b031e6be2..22a1c6aac8c 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -2874,6 +2874,12 @@ supplement_binding (cxx_binding *binding, tree decl) "%<-std=c++2c%> or %<-std=gnu++2c%>"); binding->value = name_lookup::ambiguous (decl, binding->value); } + else if (binding->scope->kind != sk_class + && TREE_CODE (decl) == USING_DECL + && decls_match (target_bval, target_decl)) + /* Since P1787 (DR 36) it is OK to redeclare entities via using-decl, + except in class scopes. */ + ok = false; else { if (!error_operand_p (bval)) @@ -5375,8 +5381,7 @@ do_nonmember_using_decl (name_lookup &lookup, bool fn_scope_p, else if (value /* Ignore anticipated builtins. */ && !anticipated_builtin_p (value) - && (fn_scope_p - || !decls_match (lookup.value, strip_using_decl (value)))) + && !decls_match (lookup.value, strip_using_decl (value))) { diagnose_name_conflict (lookup.value, value); failed = true; @@ -6648,9 +6653,6 @@ push_using_decl_bindings (name_lookup *lookup, tree name, tree value) type = binding->type; } - /* DR 36 questions why using-decls at function scope may not be - duplicates. Disallow it, as C++11 claimed and PR 20420 - implemented. */ if (lookup) do_nonmember_using_decl (*lookup, true, true, &value, &type); diff --git a/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C b/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C index 34f8bf4fa0b..4638181c63c 100644 --- a/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C +++ b/gcc/testsuite/g++.dg/cpp0x/using-enum-3.C @@ -9,7 +9,7 @@ void f () { enum e { a }; - using e::a; // { dg-error "redeclaration" } + using e::a; // { dg-bogus "redeclaration" "P1787" } // { dg-error "enum" "" { target { ! c++2a } } .-1 } } diff --git a/gcc/testsuite/g++.dg/cpp2a/using-enum-11.C b/gcc/testsuite/g++.dg/cpp2a/using-enum-11.C new file mode 100644 index 00000000000..ff99ed422d5 --- /dev/null +++ b/gcc/testsuite/g++.dg/cpp2a/using-enum-11.C @@ -0,0 +1,9 @@ +// PR c++/116160 +// { dg-do compile { target c++20 } } + +enum class Blah { b }; +void foo() { + using Blah::b; + using Blah::b; + using enum Blah; +} diff --git a/gcc/testsuite/g++.dg/lookup/using53.C b/gcc/testsuite/g++.dg/lookup/using53.C index e91829e939a..8279c73bfc4 100644 --- a/gcc/testsuite/g++.dg/lookup/using53.C +++ b/gcc/testsuite/g++.dg/lookup/using53.C @@ -52,5 +52,5 @@ void f () { using N::i; - using N::i; // { dg-bogus "conflicts" "See P1787 (CWG36)" { xfail *-*-* } } + using N::i; // { dg-bogus "conflicts" "See P1787 (CWG36)" } }