From: Nathan Sidwell <nathan@acm.org>
To: Nathaniel Shead <nathanieloshead@gmail.com>, gcc-patches@gcc.gnu.org
Cc: Jason Merrill <jason@redhat.com>
Subject: Re: [PATCH] c++: Check module attachment instead of purview when necessary [PR112631]
Date: Thu, 23 Nov 2023 15:03:37 -0500 [thread overview]
Message-ID: <dfe10dcc-113c-4dda-8128-59220e71f2b4@acm.org> (raw)
In-Reply-To: <655b2b3f.a70a0220.ca3c4.d564@mx.google.com>
On 11/20/23 04:47, Nathaniel Shead wrote:
> Bootstrapped and regtested on x86_64-pc-linux-gnu. I don't have write
> access.
>
> -- >8 --
>
> Block-scope declarations of functions or extern values are not allowed
> when attached to a named module. Similarly, class member functions are
> not inline if attached to a named module. However, in both these cases
> we currently only check if the declaration is within the module purview;
> it is possible for such a declaration to occur within the module purview
> but not be attached to a named module (e.g. in an 'extern "C++"' block).
> This patch makes the required adjustments.
Ah I'd been puzzling over the default inlinedness of member-fns of block-scope
structs. Could you augment the testcase to make sure that's right too?
Something like:
// dg-module-do link
export module Mod;
export auto Get () {
struct X { void Fn () {} };
return X();
}
///
import Mod
void Frob () { Get().Fn(); }
>
> PR c++/112631
>
> gcc/cp/ChangeLog:
>
> * cp-tree.h (named_module_attach_p): New function.
> * decl.cc (start_decl): Use named_module_attach_p instead of
> named_module_purview_p.
> (grokmethod): Likewise.
>
> gcc/testsuite/ChangeLog:
>
> * g++.dg/modules/pr112631.C: New test.
> ---
> gcc/cp/cp-tree.h | 2 ++
> gcc/cp/decl.cc | 10 +++++-----
> gcc/testsuite/g++.dg/modules/pr112631.C | 8 ++++++++
> 3 files changed, 15 insertions(+), 5 deletions(-)
> create mode 100644 gcc/testsuite/g++.dg/modules/pr112631.C
>
> diff --git a/gcc/cp/cp-tree.h b/gcc/cp/cp-tree.h
> index 7b0b7c6a17e..9a3981cef58 100644
> --- a/gcc/cp/cp-tree.h
> +++ b/gcc/cp/cp-tree.h
> @@ -7315,6 +7315,8 @@ inline bool module_attach_p ()
>
> inline bool named_module_purview_p ()
> { return named_module_p () && module_purview_p (); }
> +inline bool named_module_attach_p ()
> +{ return named_module_p () && module_attach_p (); }
>
> /* We're currently exporting declarations. */
> inline bool module_exporting_p ()
> diff --git a/gcc/cp/decl.cc b/gcc/cp/decl.cc
> index e6f75d771e0..395f108aec7 100644
> --- a/gcc/cp/decl.cc
> +++ b/gcc/cp/decl.cc
> @@ -5917,10 +5917,10 @@ start_decl (const cp_declarator *declarator,
> {
> /* A function-scope decl of some namespace-scope decl. */
> DECL_LOCAL_DECL_P (decl) = true;
> - if (named_module_purview_p ())
> + if (named_module_attach_p ())
> error_at (declarator->id_loc,
> - "block-scope extern declaration %q#D not permitted"
> - " in module purview", decl);
> + "block-scope extern declaration %q#D must not be"
> + " attached to a named module", decl);
> }
>
> /* Enter this declaration into the symbol table. Don't push the plain
> @@ -18513,10 +18513,10 @@ grokmethod (cp_decl_specifier_seq *declspecs,
> check_template_shadow (fndecl);
>
> /* p1779 ABI-Isolation makes inline not a default for in-class
> - definitions in named module purview. If the user explicitly
> + definitions attached to a named module. If the user explicitly
> made it inline, grokdeclarator will already have done the right
> things. */
> - if ((!named_module_purview_p ()
> + if ((!named_module_attach_p ()
> || flag_module_implicit_inline
> /* Lambda's operator function remains inline. */
> || LAMBDA_TYPE_P (DECL_CONTEXT (fndecl)))
> diff --git a/gcc/testsuite/g++.dg/modules/pr112631.C b/gcc/testsuite/g++.dg/modules/pr112631.C
> new file mode 100644
> index 00000000000..b5e81a1041b
> --- /dev/null
> +++ b/gcc/testsuite/g++.dg/modules/pr112631.C
> @@ -0,0 +1,8 @@
> +// { dg-additional-options "-fmodules-ts" }
> +// { dg-module-cmi bla }
> +
> +export module bla;
> +
> +extern "C++" inline void fun() {
> + void oops(); // { dg-bogus "block-scope extern declaration" }
> +}
--
Nathan Sidwell
next prev parent reply other threads:[~2023-11-23 20:03 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2023-11-20 9:47 Nathaniel Shead
2023-11-23 20:03 ` Nathan Sidwell [this message]
2023-11-27 4:59 ` Nathaniel Shead
2024-03-08 2:55 ` [PATCH v2] c++: Check module attachment instead of just " Nathaniel Shead
2024-03-08 15:19 ` Jason Merrill
2024-03-08 23:18 ` Nathaniel Shead
2024-03-11 18:13 ` Jason Merrill
2024-03-16 11:23 ` [PATCH v3] c++: Fix handling of no-linkage decls for modules Nathaniel Shead
2024-03-19 0:58 ` Jason Merrill
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=dfe10dcc-113c-4dda-8128-59220e71f2b4@acm.org \
--to=nathan@acm.org \
--cc=gcc-patches@gcc.gnu.org \
--cc=jason@redhat.com \
--cc=nathanieloshead@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).