aboutsummaryrefslogtreecommitdiff
path: root/gcc
diff options
context:
space:
mode:
authorNathan Sidwell <nathan@acm.org>2021-03-08 10:37:03 -0800
committerNathan Sidwell <nathan@acm.org>2021-03-08 10:40:09 -0800
commit504450c708ca85fe41a09924630fec945bab913b (patch)
tree780e06cb090a96316b4bad37c848f6dfb52ce1e7 /gcc
parentcb25dea3ef2c7768007bffc56f0e31e1c42b44e2 (diff)
downloadgcc-504450c708ca85fe41a09924630fec945bab913b.zip
gcc-504450c708ca85fe41a09924630fec945bab913b.tar.gz
gcc-504450c708ca85fe41a09924630fec945bab913b.tar.bz2
c++: Poor diagnostic in header-unit [PR 99468]
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.
Diffstat (limited to 'gcc')
-rw-r--r--gcc/cp/lex.c2
-rw-r--r--gcc/cp/parser.c8
-rw-r--r--gcc/testsuite/g++.dg/modules/pr99468.H7
3 files changed, 15 insertions, 2 deletions
diff --git a/gcc/cp/lex.c b/gcc/cp/lex.c
index c83346b..73e14b8 100644
--- a/gcc/cp/lex.c
+++ b/gcc/cp/lex.c
@@ -515,7 +515,7 @@ struct module_token_filter
{
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))
diff --git a/gcc/cp/parser.c b/gcc/cp/parser.c
index 378e457..f636bb7 100644
--- a/gcc/cp/parser.c
+++ b/gcc/cp/parser.c
@@ -13745,7 +13745,13 @@ cp_parser_module_declaration (cp_parser *parser, module_parse mp_state,
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. */
diff --git a/gcc/testsuite/g++.dg/modules/pr99468.H b/gcc/testsuite/g++.dg/modules/pr99468.H
new file mode 100644
index 0000000..b6be0c3
--- /dev/null
+++ b/gcc/testsuite/g++.dg/modules/pr99468.H
@@ -0,0 +1,7 @@
+// 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" }