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)" } }