https://gcc.gnu.org/bugzilla/show_bug.cgi?id=120149

            Bug ID: 120149
           Summary: ICE in GCC when deducing return type with nested
                    lambdas using accumulate 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: ---

Compiling the following valid C++ code causes an internal compiler error (ICE)
in recent versions of GCC

```
#include <vector>
#include <numeric>
using namespace std;
template<class A, class B>
auto f(A a, B b)
        -> decltype(accumulate(begin(a), end(a), B{},
                [](B t, A i) -> B
                {
                        return t + i * i;
                }))
{

}
int main()
{
        vector<int> v;


  int i;
        f(v, i);
        return  0;
}
```

```
internal compiler error: error reporting routines re-entered.
0x228730d diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x2287465 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x22983b0 error_at(rich_location*, char const*, ...)
        ???:0
0x8063af build_new_op(op_location_t const&, tree_code, int, tree_node*,
tree_node*, tree_node*, tree_node*, tree_node**, int)
        ???:0
0xa049f2 build_x_binary_op(op_location_t const&, tree_code, tree_node*,
tree_code, tree_node*, tree_code, tree_node*, tree_node**, int)
        ???:0
0x9b8831 tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x9ab9bc tsubst(tree_node*, tree_node*, int, tree_node*)
        ???:0
0x22a4c53 pretty_printer::format(text_info&)
        ???:0
0x22a6ed3 pp_verbatim(pretty_printer*, char const*, ...)
        ???:0
0x2296158 diagnostic_text_output_format::on_report_diagnostic(diagnostic_info
const&, diagnostic_t)
        ???:0
0x2287092 diagnostic_context::report_diagnostic(diagnostic_info*)
        ???:0
0x2287465 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
        ???:0
0x229746e warning_at(rich_location*, diagnostic_option_id, char const*, ...)
        ???:0
0x884c40 finish_function(bool)
        ???:0
0x99f62f instantiate_decl(tree_node*, bool, bool)
        ???:0
0x9c5b03 instantiate_pending_templates(int)
        ???:0
0x898b1a c_parse_final_cleanups()
        ???:0
0xa8b768 c_common_parse_file()
        ???:0
```

To reproduce:

Happens since gcc 10, the first version that accepts -std=c++20

https://gcc.godbolt.org/z/GMnch3Evo

Reply via email to