]> git.ipfire.org Git - thirdparty/gcc.git/commitdiff
c++/modules: Improve diagnostic when redeclaring builtin in module [PR102345]
authorNathaniel Shead <nathanieloshead@gmail.com>
Fri, 24 May 2024 15:03:54 +0000 (01:03 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Sat, 25 May 2024 00:31:55 +0000 (10:31 +1000)
If a user mistakenly includes a standard library header within the
module purview, they currently get a confusing "declaration conflicts
with builtin" error.  This patch updates the message to include "in
module", to help guide the user towards the likely cause.

PR c++/102345

gcc/cp/ChangeLog:

* module.cc (module_may_redeclare): Update error message.

gcc/testsuite/ChangeLog:

* g++.dg/modules/enum-12.C: Test for updated error.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
gcc/cp/module.cc
gcc/testsuite/g++.dg/modules/enum-12.C

index 6cd7d9e0b931123068489085c6e8fd373dc5d979..3f8f84bb9fd2ccd206f925c2043b3c608b3e37a0 100644 (file)
@@ -19140,7 +19140,13 @@ module_may_redeclare (tree olddecl, tree newdecl)
   decl = newdecl ? newdecl : olddecl;
   location_t loc = newdecl ? DECL_SOURCE_LOCATION (newdecl) : input_location;
   if (DECL_IS_UNDECLARED_BUILTIN (olddecl))
-    error_at (loc, "declaration %qD conflicts with builtin", decl);
+    {
+      if (newdecl_attached_p)
+       error_at (loc, "declaring %qD in module %qs conflicts with builtin "
+                 "in global module", decl, new_mod->get_flatname ());
+      else
+       error_at (loc, "declaration %qD conflicts with builtin", decl);
+    }
   else if (DECL_LANG_SPECIFIC (old_inner) && DECL_MODULE_IMPORT_P (old_inner))
     {
       auto_diagnostic_group d;
index 064f220dedf1344f83748ada840a8f09fc967739..cf8f445e0763658353a741915b78672966ef5a41 100644 (file)
@@ -4,7 +4,7 @@
 
 export module foo;
 namespace std {
-  enum class align_val_t : decltype(sizeof(int)) {};  // { dg-error "conflicts with builtin" }
+  enum class align_val_t : decltype(sizeof(int)) {};  // { dg-error "in module .foo. conflicts with builtin" }
 }
 
 // { dg-prune-output "not writing module" }