On 9/27/24 1:59 AM, Nathaniel Shead wrote:
Bootstrapped and regtested on x86_64-pc-linux-gnu and aarch64-unknown-linux-gnu,
OK for trunk?
-- >8 --
By [module.interface] p3, if an exported declaration is not within a
header unit, it shall not declare a name with internal linkage.
Unfortunately we cannot just do this within set_originating_module,
since at the locations its called the linkage for declarations are not
always fully determined yet. We could move the calls but this causes
the checking assertion to fail as the originating module declaration may
have moved, and in general for some kinds of declarations it's not
always obvious where it should be moved to.
This patch instead introduces a new function to check that the linkage
of a declaration within a module is correct, to be called for all
declarations once their linkage is fully determined.
As a drive-by fix this patch also improves the source location of
namespace aliases to point at the identifier rather than the terminating
semicolon.
@@ -19926,11 +19926,34 @@ set_originating_module (tree decl, bool friend_p
ATTRIBUTE_UNUSED)
DECL_MODULE_ATTACH_P (decl) = true;
}
- if (!module_exporting_p ())
+ /* It is illegal to export a declaration with internal linkage. However, at
s/illegal/ill-formed/
@@ -9249,8 +9251,13 @@ push_namespace (tree name, bool make_inline)
if (TREE_PUBLIC (ns))
DECL_MODULE_EXPORT_P (ns) = true;
else if (!header_module_p ())
- error_at (input_location,
- "exporting namespace with internal linkage");
+ {
+ if (name)
+ error_at (input_location,
+ "exporting namespace %qD with internal linkage", ns);
Since a namespace can only have internal linkage if it's within an
unnamed namespace, maybe mention that?
+ else
+ error_at (input_location, "exporting anonymous namespace");
Let's move away from using the word "anonymous" for unnamed namespaces.
Jason