When only doing preprocessing, we do not call declare_module, and so we
do not check that a module has been declared multiple times. This means
we end up with multiple "primary modules" being passed to the dependency
producing logic, which asserts. Fixed by checking if we've already seen
a module declaration and complaining.
PR c++/123738
gcc/cp/ChangeLog:
* module.cc (preprocess_module): Complain for any non-imported
module declaration in a module purview.
gcc/testsuite/ChangeLog:
* g++.dg/modules/dep-5.C: New test.
Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
{
if (!is_import)
{
- if (module->loc)
- /* It's already been mentioned, so ignore its module-ness. */
- is_import = true;
+ if (in_purview || module->loc)
+ {
+ /* We've already seen a module declaration. If only preprocessing
+ then we won't complain in declare_module, so complain here. */
+ if (flag_preprocess_only)
+ error_at (from_loc,
+ in_purview
+ ? G_("module already declared")
+ : G_("module already imported"));
+ /* Always pretend this was an import to aid error recovery. */
+ is_import = true;
+ }
else
{
/* Record it is the module. */
--- /dev/null
+// { dg-additional-options "-fmodules -M" }
+
+export module A.B:X.Y;
+export module A.B:X.Y; // { dg-error "module already declared" }
+export module F; // { dg-error "module already declared" }