]> git.ipfire.org Git - thirdparty/gcc.git/commit
c++/modules: Improve errors for bad module-directives [PR115200]
authorNathaniel Shead <nathanieloshead@gmail.com>
Thu, 23 May 2024 14:08:57 +0000 (00:08 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Fri, 24 May 2024 14:10:42 +0000 (00:10 +1000)
commitdae606a11eb99814e452b49241fa76f7678f53b8
tree9d1ff2aa2e2bf31d53a3009b207fc206a25120be
parent03531ec45f15aa187bbab7842a1eb6cf746a104b
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 <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/parser.cc
gcc/testsuite/g++.dg/modules/mod-decl-1.C
gcc/testsuite/g++.dg/modules/mod-decl-6.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/mod-decl-7.C [new file with mode: 0644]
gcc/testsuite/g++.dg/modules/mod-decl-8.C [new file with mode: 0644]