From patchwork Sun Jul 7 02:07:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1957647 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=BSll6ucp; 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 4WGrTj0kjKz1xr7 for ; Sun, 7 Jul 2024 12:16:25 +1000 (AEST) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 42B893858C52 for ; Sun, 7 Jul 2024 02:16:23 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-pl1-x634.google.com (mail-pl1-x634.google.com [IPv6:2607:f8b0:4864:20::634]) by sourceware.org (Postfix) with ESMTPS id 5198B3888C6D for ; Sun, 7 Jul 2024 02:07:59 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org 5198B3888C6D 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 5198B3888C6D Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::634 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720318086; cv=none; b=ErtecwnQgyAARMW4oWWCOghXjMhEJMXYQeYgbyQV3AbYmZAFjLfwu4/H8cIYckVlfohXTM1bnQsuAb5lls+ya4irA+87KZ4kKVs2mhLUXqk7DgdWXIqxwN30cTdJPHhzqiY/J5x5//RkLcAaolIorUpUhGpMIM6b3qpdpS+hIas= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1720318086; c=relaxed/simple; bh=2jtt+lXph0ljlsOpTSXPF+m3nOBdcZWQvUwHjMOCvl0=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=OHhmnasHDDZow5Xs2JfMRQDF3sjDE0j2jQh2FqT6YakIH+4m36hM2Dl3dUBdp4n+TmPXdM+LZbq37hQ+1gHg+YxSNMk8dB/29LHxpWKhvu+Om2+JuBDTO/zdhadQB2W9lyY1IyeLu/kd7vDfNDt/SJ4FGftIgLEY8xrn5Mw6Ti8= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-pl1-x634.google.com with SMTP id d9443c01a7336-1fb05b0be01so16532385ad.2 for ; Sat, 06 Jul 2024 19:07:59 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1720318078; x=1720922878; 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=Y+MjbBjm4k77UNzoWzqIhze5x63//ifY4pqmPCkYTCM=; b=BSll6ucpYZdGVJuG4H1Q8JR2nmWHdUKmlyI+Bkcq3sarI41j+/FxQx43rYlylpgIIO wvRZfUKA7pChxo90tsNA2GqQa93wO76G50crmFhZEjIezJ/ApMkpCGNBTRa3I76S0lXv MdV4fcKmgPdn9Pom77HnmvxteGsGAEnutM3CuWcf0b7jlalB8TI3k2BLG/whaTY1tJmK Ak5QNMRL2UnxS/SxPaTO3YgjX3d5MNjT1WbEXvJKQ0bv/IKoYZiBymQqPCqB7TWtTQGf 0wkbTm7PgmefgQZIvGWAV5Lw65uiRsS9yccFJMOYgv4ZP2bsxDb0t/RaVHcOi1YvnoCp V6rw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1720318078; x=1720922878; 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=Y+MjbBjm4k77UNzoWzqIhze5x63//ifY4pqmPCkYTCM=; b=Km27ZR7xJlVyRBwpCa7WLXed2+cnA4hvj4N1DOgJe+yMgvcuwLXCMa+wi7K8rB+Y6U lQZl29FIA6dAlYimQEiU6AVO5+hVppAlWybW5V580uN+xLdWye80MMW+SR2Y8lOtgdvs McHbcxXdRuJ/c5uO+9YasKr5yWjfUTUTnrajQEhGhkib2Ugojbk+W0nduQghCbk6RTD8 H0g6q5in3MpRvPMaWloZrMtQHWDrun2+6LYrYrFVA8l38WERDMTQZg60S3ZxAjeRZfst Nc/9LS5NzjPoQD7qXz8JPrReXAQRwhmZJQC8Jwgwo7vwojdEY6XL8JSe+BFWMJFswaNv opdA== X-Gm-Message-State: AOJu0YxKF2NoUG4PS+MQY925Vj/1X1ToOPILOYgnsITnC28aZVNaiIwP ryPF/1UqcpBf7nkoSVfeTuqXNUpq6rBc5BhR4E22MJPPPLbJ7Qd9eKlPmQ== X-Google-Smtp-Source: AGHT+IFWr3loT4Ka62c0o9n70h/gnBsgYe0Ow2L+Q/f/tNHoD/ZEv9hmymiUDaRFuHL/F8BsIBEf7g== X-Received: by 2002:a17:902:ce85:b0:1fb:7c7f:6447 with SMTP id d9443c01a7336-1fb7c7f6c77mr14016845ad.25.1720318078080; Sat, 06 Jul 2024 19:07:58 -0700 (PDT) Received: from Thaum. (125-209-140-42.tpgi.com.au. [125.209.140.42]) by smtp.gmail.com with ESMTPSA id d9443c01a7336-1fb666fdeffsm18253945ad.262.2024.07.06.19.07.56 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 06 Jul 2024 19:07:57 -0700 (PDT) Message-ID: <6689f87d.170a0220.bb973.3f98@mx.google.com> X-Google-Original-Message-ID: Date: Sun, 7 Jul 2024 12:07:53 +1000 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH 2/3] c++/modules: Handle redefinitions of using-decls MIME-Version: 1.0 Content-Disposition: inline X-Spam-Status: No, score=-12.2 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? -- >8 -- This fixes an ICE exposed by supporting exported non-function using-decls. Sometimes when preparing to define a class, xref_tag will find a using-decl belonging to a different namespace, which triggers the checking_assert in modules handling. Ideally I feel that 'lookup_and_check_tag' should be told whether we're about to define the type and handle erroring on redefinitions itself to avoid this issue (and provide better diagnostics by acknowledging the using-declaration), but this is complicated with the current fragmentation of definition checking. So for this patch we just fixup the assertion and ensure that pushdecl properly errors on the conflicting declaration later. gcc/cp/ChangeLog: * decl.cc (xref_tag): Move assertion into condition. * name-lookup.cc (check_module_override): Check for conflicting types and using-decls. gcc/testsuite/ChangeLog: * g++.dg/modules/using-19_a.C: New test. * g++.dg/modules/using-19_b.C: New test. Signed-off-by: Nathaniel Shead --- gcc/cp/decl.cc | 6 +++-- gcc/cp/name-lookup.cc | 32 ++++++++++++++++------- gcc/testsuite/g++.dg/modules/using-19_a.C | 18 +++++++++++++ gcc/testsuite/g++.dg/modules/using-19_b.C | 10 +++++++ 4 files changed, 54 insertions(+), 12 deletions(-) create mode 100644 gcc/testsuite/g++.dg/modules/using-19_a.C create mode 100644 gcc/testsuite/g++.dg/modules/using-19_b.C diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 5a823e2f94c..586dda19604 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -16737,12 +16737,14 @@ xref_tag (enum tag_types tag_code, tree name, if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t)) maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t); + /* FIXME: we should do a more precise check for redefinitions + of a conflicting using-declaration here, as these diagnostics + are not ideal. */ if (DECL_LANG_SPECIFIC (decl) && DECL_MODULE_IMPORT_P (decl) - && TREE_CODE (CP_DECL_CONTEXT (decl)) == NAMESPACE_DECL) + && CP_DECL_CONTEXT (decl) == current_namespace) { /* Push it into this TU's symbol slot. */ - gcc_checking_assert (current_namespace == CP_DECL_CONTEXT (decl)); if (maybe_tmpl != decl) /* We're in the template parm binding level. Pushtag has logic to slide under that, but we're diff --git a/gcc/cp/name-lookup.cc b/gcc/cp/name-lookup.cc index ddb4c0fe1c8..96d7f938162 100644 --- a/gcc/cp/name-lookup.cc +++ b/gcc/cp/name-lookup.cc @@ -3782,18 +3782,30 @@ check_module_override (tree decl, tree mvec, bool hiding, /* Errors could cause there to be nothing. */ continue; + tree type = NULL_TREE; if (STAT_HACK_P (bind)) - /* We do not have to check STAT_TYPE here, the xref_tag - machinery deals with that problem. */ - bind = STAT_VISIBLE (bind); + { + /* If there was a matching STAT_TYPE here then xref_tag + should have found it, but we need to check anyway because + a conflicting using-declaration may exist. */ + if (STAT_TYPE_VISIBLE_P (bind)) + type = STAT_TYPE (bind); + bind = STAT_VISIBLE (bind); + } - for (ovl_iterator iter (bind); iter; ++iter) - if (!iter.using_p ()) - { - match = duplicate_decls (decl, *iter, hiding); - if (match) - goto matched; - } + if (type) + { + match = duplicate_decls (decl, strip_using_decl (type), hiding); + if (match) + goto matched; + } + + for (ovl_iterator iter (strip_using_decl (bind)); iter; ++iter) + { + match = duplicate_decls (decl, *iter, hiding); + if (match) + goto matched; + } } if (TREE_PUBLIC (scope) && TREE_PUBLIC (STRIP_TEMPLATE (decl)) diff --git a/gcc/testsuite/g++.dg/modules/using-19_a.C b/gcc/testsuite/g++.dg/modules/using-19_a.C new file mode 100644 index 00000000000..693a70ce7d4 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-19_a.C @@ -0,0 +1,18 @@ +// { dg-additional-options "-fmodules-ts -Wno-global-module" } +// { dg-module-cmi M } + +module; + +namespace hidden { + struct S {}; + enum E { e }; + void f(); +} + +export module M; +export namespace exposed { + using hidden::S; + using hidden::E; + using hidden::e; + using hidden::f; +} diff --git a/gcc/testsuite/g++.dg/modules/using-19_b.C b/gcc/testsuite/g++.dg/modules/using-19_b.C new file mode 100644 index 00000000000..dbe8d9f3c01 --- /dev/null +++ b/gcc/testsuite/g++.dg/modules/using-19_b.C @@ -0,0 +1,10 @@ +// { dg-additional-options "-fmodules-ts" } + +import M; + +namespace exposed { + struct S {}; // { dg-error "redefinition" } + enum E { x }; // { dg-error "multiple definition" } + int e(); // { dg-error "redeclared" } + int f; // { dg-error "redeclared" } +}