c++: Standardise errors for module_may_redeclare
commit2faf040335f9b49c33ba6d40cf317920f27ce431
authorNathaniel Shead <nathanieloshead@gmail.com>
Sun, 14 Apr 2024 13:03:11 +0000 (14 23:03 +1000)
committerNathaniel Shead <nathanieloshead@gmail.com>
Tue, 30 Apr 2024 05:01:29 +0000 (30 15:01 +1000)
tree263e5c9f592bd1f1e726d472878e5d2cc6cff843
parent22b20ac6c6aead2d3f36c413a77dd0b80adfec39
c++: Standardise errors for module_may_redeclare

Currently different places calling 'module_may_redeclare' all emit very
similar but slightly different error messages, and handle different
kinds of declarations differently.  This patch makes the function
perform its own error messages so that they're all in one place, and
prepares it for use with temploid friends.

gcc/cp/ChangeLog:

* cp-tree.h (module_may_redeclare): Add default parameter.
* decl.cc (duplicate_decls): Don't emit errors for failed
module_may_redeclare.
(xref_tag): Likewise.
(start_enum): Likewise.
* semantics.cc (begin_class_definition): Likewise.
* module.cc (module_may_redeclare): Clean up logic. Emit error
messages on failure.

gcc/testsuite/ChangeLog:

* g++.dg/modules/enum-12.C: Update error message.
* g++.dg/modules/friend-5_b.C: Likewise.
* g++.dg/modules/shadow-1_b.C: Likewise.

Signed-off-by: Nathaniel Shead <nathanieloshead@gmail.com>
Reviewed-by: Jason Merrill <jason@redhat.com>
gcc/cp/cp-tree.h
gcc/cp/decl.cc
gcc/cp/module.cc
gcc/cp/semantics.cc
gcc/testsuite/g++.dg/modules/enum-12.C
gcc/testsuite/g++.dg/modules/friend-5_b.C
gcc/testsuite/g++.dg/modules/shadow-1_b.C