https://gcc.gnu.org/bugzilla/show_bug.cgi?id=115200
--- Comment #1 from GCC Commits <cvs-commit at gcc dot gnu.org> --- The master branch has been updated by Nathaniel Shead <nsh...@gcc.gnu.org>: https://gcc.gnu.org/g:dae606a11eb99814e452b49241fa76f7678f53b8 commit r15-824-gdae606a11eb99814e452b49241fa76f7678f53b8 Author: Nathaniel Shead <nathanielosh...@gmail.com> Date: Fri May 24 00:08:57 2024 +1000 c++/modules: Improve errors for bad module-directives [PR115200] This fixes an ICE when a module directive is not given at global scope. Although not explicitly mentioned, it seems implied from [basic.link] p1 and [module.global.frag] that a module-declaration must appear at the global scope after preprocessing. Apart from this the patch also slightly improves the errors given when accidentally using a module control-line in other situations where it is not expected. PR c++/115200 gcc/cp/ChangeLog: * parser.cc (cp_parser_error_1): Special-case unexpected module directives for better diagnostics. (cp_parser_module_declaration): Check that the module declaration is at global scope. (cp_parser_import_declaration): Sync error message with that in cp_parser_error_1. gcc/testsuite/ChangeLog: * g++.dg/modules/mod-decl-1.C: Update error messages. * g++.dg/modules/mod-decl-6.C: New test. * g++.dg/modules/mod-decl-7.C: New test. * g++.dg/modules/mod-decl-8.C: New test. Signed-off-by: Nathaniel Shead <nathanielosh...@gmail.com> Reviewed-by: Jason Merrill <ja...@redhat.com>