https://gcc.gnu.org/bugzilla/show_bug.cgi?id=125678
Bug ID: 125678
Summary: [C++23] ICE: error reporting routines re-entered in
tsubst_lambda_expr via pp_format on NTTP lambda
mismatch
Product: gcc
Version: 14.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: 1794833681 at qq dot com
Target Milestone: ---
Summary
[C++23] ICE: error reporting routines re-entered in tsubst_lambda_expr via
pp_format on NTTP lambda mismatch
Keywords
ice-on-invalid-code, c++, diagnostic
Description
The C++ frontend triggers an "error reporting routines re-entered" ICE when
attempting to diagnose an implicit conversion failure between two distinct NTTP
(Non-Type Template Parameter) lambdas.
Because every lambda has a unique type, returning ConfigItem<[](){}>{} in the
function body when the declared return type is also ConfigItem<[](){}> causes a
type mismatch (since they are two different closure types).
While attempting to format the error message for this failed conversion, the
pretty-printer (pp_format) invokes tsubst_lambda_expr, which triggers another
internal error and leads to the re-entrant diagnostic crash.
Minimal Reproducible Example
C++
template<auto ConfigValue>
using ConfigItem = decltype([](auto config) {
return __builtin_addressof(config);
}(ConfigValue));
template<typename... Sections>
ConfigItem<[](){}> createConfigManager() {
return ConfigItem<[](){}>{};
}
int main() {
auto configManager = createConfigManager<>();
}
Command Line Arguments
Bash
g++ -std=c++23 source.cpp
Tested Versions
Reproduced on: x86-64 gcc 14.1
Reproduced on: x86-64 gcc 14.2
Compiler Output / Backtrace
Plaintext
<source>: In function 'int main()':
<source>:12:43: internal compiler error: error reporting routines re-entered.
0x2dff055 diagnostic_context::report_diagnostic(diagnostic_info*)
???:0
0x2dff928 warning(int, char const*, ...)
???:0
0xfe99e3 start_preparsed_function(tree_node*, tree_node*, int)
???:0
0x104d8e9 start_lambda_function(tree_node*, tree_node*)
???:0
0x1174645 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0x1164e10 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x114c283 instantiate_template(tree_node*, tree_node*, int)
???:0
0x11644d5 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x2e26cd4 pp_format(pretty_printer*, text_info*, urlifier const*)
???:0
0x2e29cb5 pp_verbatim(pretty_printer*, char const*, ...)
???:0
0x2dfeeda diagnostic_context::report_diagnostic(diagnostic_info*)
???:0
0x2e03282 error_at(rich_location*, char const*, ...)
???:0
0xf43285 perform_implicit_conversion_flags(tree_node*, tree_node*, int, int)
???:0
0x11f50e4 check_return_expr(tree_node*, bool*, bool*)
???:0
0x119a258 finish_return_stmt(tree_node*)
???:0
0x115a533 instantiate_decl(tree_node*, bool, bool)
???:0
0x1183a0b instantiate_pending_templates(int)
???:0
0x101f8c9 c_parse_final_cleanups()
???:0
0x1277558 c_common_parse_file()
???:0
Please submit a full bug report, with preprocessed source (by using
-freport-bug).
Please include the complete backtrace with any bug report.
See <https://gcc.gnu.org/bugs/> for instructions.
Expected Behavior
The compiler should gracefully reject the code and emit a standard compilation
error regarding the failed implicit conversion between the two distinct lambda
closure types, rather than crashing the diagnostic system during output
formatting.