From patchwork Sun Nov 12 12:00:50 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathaniel Shead X-Patchwork-Id: 1862831 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=ImSmP15M; 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 4SSrkN1D1jz1yRV for ; Sun, 12 Nov 2023 23:01:15 +1100 (AEDT) Received: from server2.sourceware.org (localhost [IPv6:::1]) by sourceware.org (Postfix) with ESMTP id 81702385840F for ; Sun, 12 Nov 2023 12:01:08 +0000 (GMT) X-Original-To: gcc-patches@gcc.gnu.org Delivered-To: gcc-patches@gcc.gnu.org Received: from mail-il1-x130.google.com (mail-il1-x130.google.com [IPv6:2607:f8b0:4864:20::130]) by sourceware.org (Postfix) with ESMTPS id C65B83858C2F for ; Sun, 12 Nov 2023 12:00:56 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.2 sourceware.org C65B83858C2F 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 C65B83858C2F Authentication-Results: server2.sourceware.org; arc=none smtp.remote-ip=2607:f8b0:4864:20::130 ARC-Seal: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699790458; cv=none; b=eMA+w3pC6J8GFsUI2aAfuVkQeWQpx3Q+/V/Yi8uuT8oWQBGQ3U1jUp5fY4cIPUhCTetTYG+sTCN0sRDp/bAO2sB4gkn0Q29V0X13JcR5uaj/n8REO2kLY88HqRVRw9y/tPSLminyKuboVDCb7lem0naDliTIxem4Umtw+pbW2bk= ARC-Message-Signature: i=1; a=rsa-sha256; d=sourceware.org; s=key; t=1699790458; c=relaxed/simple; bh=u+X40qFBUPQPgSFbW1r6qsmpCX/bHyXNf+6BmUQvFtE=; h=DKIM-Signature:Message-ID:Date:From:To:Subject:MIME-Version; b=v40QE+MvwmHY32SZ6FAO1gxN6zNbm1+Gpg5P3R0PZHr1rLXHtoFwlmZkKcuayQT2NngFk/d1lJf2/yQGoykTzVuw4Lmy5fvxOkj3iRGSSY8OelW7uzFZxZf5sJv4dtUAGAQ+L/IRUO5jOMW5pud0mVlo23Wl/Ggkrhvia+cxGCU= ARC-Authentication-Results: i=1; server2.sourceware.org Received: by mail-il1-x130.google.com with SMTP id e9e14a558f8ab-35ab17957c3so3879585ab.3 for ; Sun, 12 Nov 2023 04:00:56 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1699790455; x=1700395255; 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=glv/B1+zpVF61E30IhzA3p3cZtloAph+IZvEvGpKz6s=; b=ImSmP15MXqvVZmGTWFPmIOHlG71KmBII5Bn51UI7H/+mUVjis1EGqY1lj6IgAzV1JM pfDNxziQjScrCiHGQDa/21MFZbP8K5PrVJquxh1rwhrGixerI8nIShNwVBNkEd4HKuRf eNyrDirZCVZrb9bt8tOYv87lTz7pOFeUCOYypjb6adqhgsx6g1rmD3daYgPlwZB7FBIJ vNLydzUJB031q2rRqNKMGzG5cjnk3/6JyX1nebtjbwPSCsbqOHn/OMmRw33J2fHc/br6 7u7+SZy44cVifeuCzJpEYHoUJ63MhS3k7JD5mSImjOJ7hfW5GYUWQR4Uc3P83tB5Ao1m etlg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1699790455; x=1700395255; 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=glv/B1+zpVF61E30IhzA3p3cZtloAph+IZvEvGpKz6s=; b=txDvMVIIn8sQQKmSrKyudVKoRoCYYnDiR1KTLHvREcgPMceN7TPZJq00xrwEzjYLWR cp+EoEsg1AsNlsakkB+oBkumziwgdctj7q4YEGe/QVNOvvKkOgDDTf5jtHu/uUY6Z1t6 CIdDCzuOPKam6P0KcIBwgJO7Ph0+XUo3JSNavVfne/tLU4YuHxi+bKSresQ2tNgLnwqi 5UZrTVBs3kR2EhlBDIu5hUKeBL2ol2uD7XA29zV7KZbYRd6TsX5EQk6U/P0hBicMBsOY T1YcgMwulYv/gXQag0K5Gl9po/tcJIIUha0M+Pj5CeJ6QPjVKJcGu94wef1unMehVhbm NG0Q== X-Gm-Message-State: AOJu0YyOu1iD46dcHvHn6jb02U+iGP8+MsLirk0twEmX3Xg5ml+F3tdv AgYDgWyttn0LWMvOoUbKfS7+6XRIQuA= X-Google-Smtp-Source: AGHT+IHCyfPcGQmjBjvW0gZHCeYuNJ6ZXr+jpwbOlgtFhClp2BfZZ+3MfbXa+RUOz87gzvD1JRqHZg== X-Received: by 2002:a05:6e02:1949:b0:357:fa1b:491 with SMTP id x9-20020a056e02194900b00357fa1b0491mr7339163ilu.5.1699790455349; Sun, 12 Nov 2023 04:00:55 -0800 (PST) Received: from Thaum. (124-150-88-161.tpgi.com.au. [124.150.88.161]) by smtp.gmail.com with ESMTPSA id jc13-20020a17090325cd00b001c5bcc9d916sm2497552plb.176.2023.11.12.04.00.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 12 Nov 2023 04:00:54 -0800 (PST) Message-ID: <6550be76.170a0220.b3f34.4f25@mx.google.com> X-Google-Original-Message-ID: Date: Sun, 12 Nov 2023 23:00:50 +1100 From: Nathaniel Shead To: gcc-patches@gcc.gnu.org Cc: Jason Merrill , Nathan Sidwell Subject: [PATCH] c++/modules: check mismatching exports for class tags [PR98885] MIME-Version: 1.0 Content-Disposition: inline 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, 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 I think the error message is still a little bit unclear but I couldn't come up with something clearer that was similarly concise and matching the existing style. (Also I noticed that the linked PR was assigned to Nathan but there hadn't been activity for a while, and I've been looking into these kinds of issues recently anyway so I thought I'd give it a go.) Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write access. -- >8 -- Checks for exporting a declaration that was previously declared as not exported is implemented in 'duplicate_decls', but this doesn't handle declarations of classes. This patch adds these checks and slightly adjusts the associated error messages for clarity. PR c++/98885 gcc/cp/ChangeLog: * decl.cc (duplicate_decls): Adjust error message. (xref_tag): Adjust error message. Check exporting decl that is already declared as non-exporting. gcc/testsuite/ChangeLog: * g++.dg/modules/export-1.C: Adjust error messages. Remove xfails for working case. Add new test case. Signed-off-by: Nathaniel Shead --- gcc/cp/decl.cc | 21 ++++++++++++++++++--- gcc/testsuite/g++.dg/modules/export-1.C | 16 +++++++++------- 2 files changed, 27 insertions(+), 10 deletions(-) diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc index 4a07c7e879b..bde9bd79d58 100644 --- a/gcc/cp/decl.cc +++ b/gcc/cp/decl.cc @@ -2236,8 +2236,10 @@ duplicate_decls (tree newdecl, tree olddecl, bool hiding, bool was_hidden) if (DECL_MODULE_EXPORT_P (STRIP_TEMPLATE (newdecl)) && !DECL_MODULE_EXPORT_P (not_tmpl)) { - error ("conflicting exporting declaration %qD", newdecl); - inform (olddecl_loc, "previous declaration %q#D here", olddecl); + auto_diagnostic_group d; + error ("conflicting exporting for declaration %qD", newdecl); + inform (olddecl_loc, + "previously declared here without exporting"); } } else if (DECL_MODULE_EXPORT_P (newdecl)) @@ -16249,11 +16251,24 @@ xref_tag (enum tag_types tag_code, tree name, tree decl = TYPE_NAME (t); if (!module_may_redeclare (decl)) { + auto_diagnostic_group d; error ("cannot declare %qD in a different module", decl); - inform (DECL_SOURCE_LOCATION (decl), "declared here"); + inform (DECL_SOURCE_LOCATION (decl), "previously declared here"); return error_mark_node; } + tree not_tmpl = STRIP_TEMPLATE (decl); + if (DECL_LANG_SPECIFIC (not_tmpl) + && DECL_MODULE_ATTACH_P (not_tmpl) + && !DECL_MODULE_EXPORT_P (not_tmpl) + && module_exporting_p ()) + { + auto_diagnostic_group d; + error ("conflicting exporting for declaration %qD", decl); + inform (DECL_SOURCE_LOCATION (decl), + "previously declared here without exporting"); + } + tree maybe_tmpl = decl; if (CLASS_TYPE_P (t) && CLASSTYPE_IS_TEMPLATE (t)) maybe_tmpl = CLASSTYPE_TI_TEMPLATE (t); diff --git a/gcc/testsuite/g++.dg/modules/export-1.C b/gcc/testsuite/g++.dg/modules/export-1.C index 8ca696ebee0..3f93814d270 100644 --- a/gcc/testsuite/g++.dg/modules/export-1.C +++ b/gcc/testsuite/g++.dg/modules/export-1.C @@ -4,19 +4,21 @@ export module frob; // { dg-module-cmi !frob } int x (); -export int x (); // { dg-error "conflicting exporting declaration" } +export int x (); // { dg-error "conflicting exporting for declaration" } int y; -export extern int y; // { dg-error "conflicting exporting declaration" } +export extern int y; // { dg-error "conflicting exporting for declaration" } typedef int z; -export typedef int z; // { dg-error "conflicting exporting declaration" } +export typedef int z; // { dg-error "conflicting exporting for declaration" } template int f (T); -export template int f (T); // { dg-error "conflicting exporting declaration" } +export template int f (T); // { dg-error "conflicting exporting for declaration" } -// doesn't go via duplicate_decls so we miss this for now class A; -export class A; // { dg-error "conflicting exporting declaration" "" { xfail *-*-* } } +export class A; // { dg-error "conflicting exporting for declaration" } -// { dg-warning "due to errors" "" { target *-*-* } 0 } +template struct B; +export template struct B {}; // { dg-error "conflicting exporting for declaration" } + +// { dg-warning "due to errors" "" { target *-*-* } 0 }