diff mbox series

[c++] : Improve module-decl diagnostics [PR 98327]

Message ID 7b3830ac-e52f-aa56-4aac-6bcf22e20406@acm.org
State New
Headers show
Series [c++] : Improve module-decl diagnostics [PR 98327] | expand

Commit Message

Nathan Sidwell Jan. 5, 2021, 1:22 p.m. UTC
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.cc (cp_parser_module_declaration): Alter diagnostic
         text to	say where is permissable.
         gcc/testsuite/
         * g++.dg/modulex/mod-decl-1.C: Adjust.
         * g++.dg/modulex/p0713-2.C: Adjust.
         * g++.dg/modulex/p0713-3.C: Adjust.
diff mbox series

Patch

diff --git i/gcc/cp/parser.c w/gcc/cp/parser.c
index d855e034458..c713852fe93 100644
--- i/gcc/cp/parser.c
+++ w/gcc/cp/parser.c
@@ -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);
     }
diff --git i/gcc/testsuite/g++.dg/modules/mod-decl-1.C w/gcc/testsuite/g++.dg/modules/mod-decl-1.C
index b2665bec743..23d34483dd7 100644
--- i/gcc/testsuite/g++.dg/modules/mod-decl-1.C
+++ w/gcc/testsuite/g++.dg/modules/mod-decl-1.C
@@ -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" }
 
diff --git i/gcc/testsuite/g++.dg/modules/p0713-2.C w/gcc/testsuite/g++.dg/modules/p0713-2.C
index c7846e450a9..cb4ccb6c5f6 100644
--- i/gcc/testsuite/g++.dg/modules/p0713-2.C
+++ w/gcc/testsuite/g++.dg/modules/p0713-2.C
@@ -1,3 +1,3 @@ 
 // { dg-additional-options "-fmodules-ts" }
 int j;
-module; // { dg-error "not permitted" }
+module; // { dg-error "only permitted as" }
diff --git i/gcc/testsuite/g++.dg/modules/p0713-3.C w/gcc/testsuite/g++.dg/modules/p0713-3.C
index 3c539ebab3e..09d89b73b3f 100644
--- i/gcc/testsuite/g++.dg/modules/p0713-3.C
+++ w/gcc/testsuite/g++.dg/modules/p0713-3.C
@@ -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" }