We didn't specifically check for a module-decl inside a header unit.
That leads to a confusing diagostic. Fixed thusly.
gcc/cp/
* lex.c (module_token_filter::resume): Ignore module-decls inside
header-unit.
* parser.c (cp_parser_module_declaration): Reject in header-unit.
gcc/testsuite/
* g++.dg/modules/pr99468.H: New.
{
module_end:;
/* End of the directive, handle the name. */
- if (import)
+ if (import && (is_import || !flag_header_unit))
if (module_state *m
= preprocess_module (import, token_loc, module != NULL,
is_import, got_export, reader))
parser->lexer->in_pragma = true;
cp_token *token = cp_lexer_consume_token (parser->lexer);
- if (mp_state == MP_FIRST && !exporting
+ if (flag_header_unit)
+ {
+ error_at (token->location,
+ "module-declaration not permitted in header-unit");
+ goto skip_eol;
+ }
+ else if (mp_state == MP_FIRST && !exporting
&& cp_lexer_next_token_is (parser->lexer, CPP_SEMICOLON))
{
/* Start global module fragment. */
--- /dev/null
+// PR 99468, stupidly worded diagnostic
+// { dg-additional-options -fmodule-header }
+
+module M; // { dg-error "module-declaration not permitted" }
+
+int i;
+// { dg-prune-output "not writing" }