diff options
author | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-05-25 01:03:54 +1000 |
---|---|---|
committer | Nathaniel Shead <nathanieloshead@gmail.com> | 2024-05-25 10:31:55 +1000 |
commit | 28b508233a12c13295f960a2cb8a4864879acfb4 (patch) | |
tree | adb51a279ef16bbc659ada1db478857b9f648f68 /gcc/cp/module.cc | |
parent | 6c0b7e12e51cfcc58d6b7dfe9c822c7a720fddd7 (diff) | |
download | gcc-28b508233a12c13295f960a2cb8a4864879acfb4.zip gcc-28b508233a12c13295f960a2cb8a4864879acfb4.tar.gz gcc-28b508233a12c13295f960a2cb8a4864879acfb4.tar.bz2 |
c++/modules: Improve diagnostic when redeclaring builtin in module [PR102345]
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>
Diffstat (limited to 'gcc/cp/module.cc')
-rw-r--r-- | gcc/cp/module.cc | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/gcc/cp/module.cc b/gcc/cp/module.cc index 6cd7d9e..3f8f84b 100644 --- a/gcc/cp/module.cc +++ b/gcc/cp/module.cc @@ -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; |