From patchwork Thu Jun 13 14:59:08 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jason Merrill X-Patchwork-Id: 1947449 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@legolas.ozlabs.org Authentication-Results: legolas.ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=redhat.com header.i=@redhat.com header.a=rsa-sha256 header.s=mimecast20190719 header.b=iFDR8jOz; dkim-atps=neutral Authentication-Results: legolas.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gcc.gnu.org (client-ip=8.43.85.97; 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 [8.43.85.97]) (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 4W0QZD5x4Vz1ydW for ; Fri, 14 Jun 2024 01:00:20 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 00BA43882130 for ; Thu, 13 Jun 2024 15:00:19 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by sourceware.org (Postfix) with ESMTPS id 8E8C63882052 for ; Thu, 13 Jun 2024 14:59:57 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 8E8C63882052 Authentication-Results: sourceware.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: sourceware.org; spf=pass smtp.mailfrom=redhat.com ARC-Filter: OpenARC Filter v1.0.0 sourceware.org 8E8C63882052 Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718290799; cv=none; b=XAUWx3kMQ9dq4zsqaoyuga11i0kUVGHCyhdF1wMRcc1MTB6OuYIWius8tSWqpRjXXmKa/AioyiMMRReddoPCloFsSzYI2zVzE0ntreOnIOEsIRqr2IOPjUsiiEOSj3ujw0awwGvxvWVkPIHMNN5ZZvYVf8YHRis8vpT/uZt//fY= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1718290799; c=relaxed/simple; bh=q8UjYuoB4IhGH1aO2JD9/gjXb4antFgzva4oL7JmwxA=; h=DKIM-Signature:From:To:Subject:Date:Message-ID:MIME-Version; b=d5DCBRtezhZncYrkzgK6K6XzqNZIToEy1BHaSbI9maaPCwPLW31nSavl2ngD46daraIw1QpMMDAsZD5HASilYTPigQSDumooorM4OCs+SlgPEULQMHe6ElOdx9aHfS60XLIl62Ac0QDcn5xpMdNp/31oqY753LLHTU+i6+u4m4c= ARC-Authentication-Results: i=1; server2.sourceware.org DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1718290797; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=2OizBNqkVVBnFMOAAJDG0QzPSqB7eyL2bdjOVe20oHI=; b=iFDR8jOzdSapireUzvvOB1BnV1xS1YBt35NUyssVGn/KcwmL8IEe/2leUJBGl0O1v1Q7tb lmzP8zvDvF6nf8NXuyuFz55HCRnX0z9fK0YOSyNCbNlCe5ftIK3wyQLcKF+pIW6zfWdLmH dnkrqK+yYr1K9s2+q1doX1rqirMUtyk= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-321-Q9-QUIGaP2i7QCptUb7j_A-1; Thu, 13 Jun 2024 10:59:56 -0400 X-MC-Unique: Q9-QUIGaP2i7QCptUb7j_A-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-795d19c522eso137425785a.1 for ; Thu, 13 Jun 2024 07:59:56 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1718290795; x=1718895595; h=content-transfer-encoding:mime-version:message-id:date:subject:cc :to:from:x-gm-message-state:from:to:cc:subject:date:message-id :reply-to; bh=2OizBNqkVVBnFMOAAJDG0QzPSqB7eyL2bdjOVe20oHI=; b=X1yZ6RaAOxDgrNXiJdbB0egrzsOjcYW6WDMxHGo+gzNIOYMeCik15y31uwa936Gmvu TiFrnpxWZcQpA+Rpq6W5Kjn2KrQTa7vZlp6EcjApzaULQknKUPWW8chVSilVlbatCRC4 FovH1tDWtM6rrEWl/Vxv2I4VeqFJ3IEmScuoGxTEGbfyXDZXS0FBldLi9bxcDV6e+xnb p1BVdhPd0mgnZxIU3jXQRnyTvdLjMBuldTTWAfKQgy7vwhGHGJ6+4rqkjgpQzzLT3LTl oQpCSSu455XY4HVETXQppnox6+JgmcerELNVzQBYEOaBc2OWp95UNsowKPyqKWikYMgO 2F5w== X-Gm-Message-State: AOJu0Yy69Et5YuvQzBxgtGnL46n2wQ2dDWMVEGAm1xqddY03axpjsFDg Zm64Ip1RYLM4JQ5C9aD0skUHs5s7u5wWFag7eeb37Sw9RaE34VdscXDqIa4PKGnkA7h3/rSPT4R 2HbgwexWL3BJ93UAeG1BpvndYp6vr8pqZvylyGeqlTGYB7IGtNms37yYnoI59bvKae2s405XeTg 6jFU57OcJ+G3mlv0Wte40n0j8dvvyA5KhXsWQ= X-Received: by 2002:a05:620a:372a:b0:792:6918:de9c with SMTP id af79cd13be357-797f6129136mr628314685a.73.1718290795178; Thu, 13 Jun 2024 07:59:55 -0700 (PDT) X-Google-Smtp-Source: AGHT+IHVyyDBVD+pyS6YRvFoSVUjrPzJpgW3vIIkKBE3pEWM2NUQgn9tna4udU/1s28kbh71ZECI1w== X-Received: by 2002:a05:620a:372a:b0:792:6918:de9c with SMTP id af79cd13be357-797f6129136mr628312685a.73.1718290794837; Thu, 13 Jun 2024 07:59:54 -0700 (PDT) Received: from jason-thinkpadp1gen4i.rmtusma.csb (130-44-146-16.s12558.c3-0.arl-cbr1.sbo-arl.ma.cable.rcncustomer.com. [130.44.146.16]) by smtp.gmail.com with ESMTPSA id af79cd13be357-798aaeeba56sm58325285a.52.2024.06.13.07.59.54 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 13 Jun 2024 07:59:54 -0700 (PDT) From: Jason Merrill To: gcc-patches@gcc.gnu.org Cc: Nathaniel Shead Subject: [pushed] c++/modules: multiple usings of the same decl [PR115194] Date: Thu, 13 Jun 2024 10:59:08 -0400 Message-ID: <20240613145952.2715237-1-jason@redhat.com> X-Mailer: git-send-email 2.44.0 MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-Spam-Status: No, score=-12.3 required=5.0 tests=BAYES_00, DKIMWL_WL_HIGH, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_NONE, RCVD_IN_MSPIKE_H4, RCVD_IN_MSPIKE_WL, SPF_HELO_NONE, SPF_NONE, TXREP, T_SCC_BODY_TEXT_LINE 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 Tested x86_64-pc-linux-gnu, applying to trunk. -- 8< -- add_binding_entity creates an OVERLOAD to represent a using-declaration in module purview of a declaration in the global module, even for non-functions, and we were failing to merge that with the original declaration in name lookup. It's not clear to me that building the OVERLOAD is what should be happening, but let's work around it for now pending an overhaul of using-decl handling for c++/114683. PR c++/115194 gcc/cp/ChangeLog: * name-lookup.cc (name_lookup::process_module_binding): Strip an OVERLOAD from a non-function. gcc/testsuite/ChangeLog: * g++.dg/modules/using-23_a.C: New test. * g++.dg/modules/using-23_b.C: New test. --- gcc/cp/name-lookup.cc | 11 +++++++++++ gcc/testsuite/g++.dg/modules/using-23_a.C | 19 +++++++++++++++++++ gcc/testsuite/g++.dg/modules/using-23_b.C | 7 +++++++ 3 files changed, 37 insertions(+) create mode 100644 gcc/testsuite/g++.dg/modules/using-23_a.C create mode 100644 gcc/testsuite/g++.dg/modules/using-23_b.C base-commit: 99e6cf404e37655be303e71f20df03c284c7989e diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index 3d3e20f48cb..71482db7b76 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -827,6 +827,17 @@ name_lookup::process_module_binding (tree new_val, tree new_type, marker |= 2; } + /* add_binding_entity wraps decls brought in by 'using' in an OVERLOAD even + for non-functions; strip it now. + ??? Why isn't it represented with a USING_DECL? Or do we want to use + OVERLOAD for using more widely to address 114683? */ + if (new_val && TREE_CODE (new_val) == OVERLOAD + && !DECL_DECLARES_FUNCTION_P (OVL_FUNCTION (new_val))) + { + gcc_checking_assert (OVL_USING_P (new_val) && !OVL_CHAIN (new_val)); + new_val = OVL_FUNCTION (new_val); + } + if (new_type || new_val) marker |= process_binding (new_val, new_type); diff --git a/gcc/testsuite/g++.dg/modules/using-23_a.C b/gcc/testsuite/g++.dg/modules/using-23_a.C new file mode 100644 index 00000000000..e7e6fecbea6 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-23_a.C @@ -0,0 +1,19 @@ +// PR c++/115194 +// { dg-additional-options "-fmodules-ts -Wno-global-module" } + +module; + +namespace NS1 { + namespace NS2 { + class Thing {}; + } // NS2 + using NS2::Thing; +} // NS1 + +export module modA; + +export +namespace NS1 { + using ::NS1::Thing; + namespace NS2 { } +} diff --git a/gcc/testsuite/g++.dg/modules/using-23_b.C b/gcc/testsuite/g++.dg/modules/using-23_b.C new file mode 100644 index 00000000000..6502c476b9b --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-23_b.C @@ -0,0 +1,7 @@ +// { dg-additional-options "-fmodules-ts" } + +import modA; + +using NS1::Thing; +using namespace NS1::NS2; +Thing thing;