https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120197
Bug ID: 120197 Summary: ICE in GCC with decltype(cout << a) in default function parameter leads to recursive diagnostics with -std=c++20 Product: gcc Version: 16.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: mario.rodriguezb1 at um dot es Target Milestone: --- Using decltype(cout << a) as a default argument causes GCC to enter error-reporting routines recursively when a is deduced to a stream type, leading to an internal compiler error. ``` #include <iostream> using namespace std; template <class T> void myFunc(T a, decltype(cout << a) o=cout) { cout << o << endl; } int main() { myFunc(5); } ``` Not a specific ICE is shown in trunk, just: internal compiler error: error reporting routines re-entered. ``` internal compiler error: error reporting routines re-entered. internal compiler error: error reporting routines re-entered. 0x293b1be diagnostic_context::report_diagnostic(diagnostic_info*) ???:0 0x293b2d5 diagnostic_context::diagnostic_impl(rich_location*, diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag (*) [1], diagnostic_t) ???:0 0x2954bdf error_at(unsigned long, char const*, ...) ???:0 0xb59baa satisfaction_cache::get() ???:0 0xb60248 constraints_satisfied_p(tree_node*, tree_node*) ???:0 0xd32096 tsubst(tree_node*, tree_node*, int, tree_node*) ???:0 0xd3176b tsubst(tree_node*, tree_node*, int, tree_node*) ???:0 0xd4e9bd instantiate_template(tree_node*, tree_node*, int) ???:0 0xd59dc6 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node* const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool, bool) ???:0 0xb104a6 build_new_op(op_location_t const&, tree_code, int, tree_node*, tree_node*, tree_node*, tree_node*, tree_node**, int) ???:0 0xdbada2 build_x_binary_op(op_location_t const&, tree_code, tree_node*, tree_code, tree_node*, tree_code, tree_node*, tree_node**, int) ???:0 0xd3195d tsubst(tree_node*, tree_node*, int, tree_node*) ???:0 0x2978ca3 pretty_printer::format(text_info&) ???:0 0x297e463 pp_verbatim(pretty_printer*, char const*, ...) ???:0 0x29529a8 diagnostic_text_output_format::on_report_diagnostic(diagnostic_info const&, diagnostic_t) ???:0 0x293ae26 diagnostic_context::report_diagnostic(diagnostic_info*) ???:0 0x293b2d5 diagnostic_context::diagnostic_impl(rich_location*, diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag (*) [1], diagnostic_t) ???:0 0x29552f6 internal_error(char const*, ...) ???:0 0xad6166 fancy_abort(char const*, int, char const*) ???:0 0x293a6eb diagnostic_context::finish() ???:0 ``` It happens in trunk and from version 11.2 https://gcc.godbolt.org/z/zz6d3ezrf