mirror of
git://gcc.gnu.org/git/gcc.git
synced 2025-04-18 11:40:54 +08:00
[c++]: Improve module-decl diagnostics [PR 98327]
The diagnostic for a misplaced module decl was essentially 'computer says no', which isn't the most helpful. This adjusts it to indicate what would be acceptable. gcc/cp/ * parser.c (cp_parser_module_declaration): Alter diagnostic text to say where is permissable. gcc/testsuite/ * g++.dg/modules/mod-decl-1.C: Adjust. * g++.dg/modules/p0713-2.C: Adjust. * g++.dg/modules/p0713-3.C: Adjust.
This commit is contained in:
parent
af60b0ec79
commit
6ffaffd5d1
@ -13726,19 +13726,22 @@ cp_parser_module_declaration (cp_parser *parser, module_parse mp_state,
|
||||
cp_lexer_consume_token (parser->lexer);
|
||||
cp_parser_require_pragma_eol (parser, token);
|
||||
|
||||
if ((mp_state != MP_PURVIEW && mp_state != MP_PURVIEW_IMPORTS)
|
||||
if (!(mp_state == MP_PURVIEW || mp_state == MP_PURVIEW_IMPORTS)
|
||||
|| !module_interface_p () || module_partition_p ())
|
||||
error_at (token->location,
|
||||
"private module fragment not permitted here");
|
||||
"private module fragment only permitted in purview"
|
||||
" of module interface or partition");
|
||||
else
|
||||
{
|
||||
mp_state = MP_PRIVATE_IMPORTS;
|
||||
sorry_at (token->location, "private module fragment");
|
||||
}
|
||||
}
|
||||
else if (mp_state != MP_FIRST && mp_state != MP_GLOBAL)
|
||||
else if (!(mp_state == MP_FIRST || mp_state == MP_GLOBAL))
|
||||
{
|
||||
error_at (token->location, "module-declaration not permitted here");
|
||||
/* Neither the first declaration, nor in a GMF. */
|
||||
error_at (token->location, "module-declaration only permitted as first"
|
||||
" declaration, or ending a global module fragment");
|
||||
skip_eol:
|
||||
cp_parser_skip_to_pragma_eol (parser, token);
|
||||
}
|
||||
|
@ -6,11 +6,11 @@ export module frist;
|
||||
|
||||
import frist; // { dg-error {cannot import module.* in its own purview} }
|
||||
|
||||
module foo.second; // { dg-error "not permitted here" }
|
||||
module foo.second; // { dg-error "only permitted as" }
|
||||
|
||||
namespace Foo
|
||||
{
|
||||
module third; // { dg-error "not permitted here" }
|
||||
module third; // { dg-error "only permitted as" }
|
||||
}
|
||||
|
||||
struct Baz
|
||||
@ -23,7 +23,7 @@ void Bink ()
|
||||
module fifth; // { dg-error "expected" }
|
||||
}
|
||||
|
||||
module a.; // { dg-error "not permitted" }
|
||||
module a.; // { dg-error "only permitted as" }
|
||||
|
||||
// { dg-prune-output "not writing module" }
|
||||
|
||||
|
@ -1,3 +1,3 @@
|
||||
// { dg-additional-options "-fmodules-ts" }
|
||||
int j;
|
||||
module; // { dg-error "not permitted" }
|
||||
module; // { dg-error "only permitted as" }
|
||||
|
@ -1,6 +1,6 @@
|
||||
// { dg-additional-options "-fmodules-ts" }
|
||||
int k;
|
||||
module frob; // { dg-error "not permitted" }
|
||||
module frob; // { dg-error "only permitted as" }
|
||||
// { dg-prune-output "failed to read" }
|
||||
// { dg-prune-output "fatal error:" }
|
||||
// { dg-prune-output "compilation terminated" }
|
||||
|
Loading…
x
Reference in New Issue
Block a user