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

            Bug ID: 101430
           Summary: Passing a lambda as a template argument causes
                    internal compiler error
           Product: gcc
           Version: 11.1.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: jorg.brown at gmail dot com
  Target Milestone: ---

This code causes gcc 11.1.0 to ICE:
////////////////////
extern "C" {
  int printf(const char *, ...);
}

void g(int n) { printf("%d\n", n); }

template<auto Lambda = []{ g(1);} > void f(decltype(Lambda) x = {}) {
    x();
}

int main() {
    constexpr auto a = []{ g(3); };
//    f<a>();

    f<[]{g(2);}>();

    f();
}
////////////////////
Output when compiled:


x86-64 gcc 11.1 (Editor #1, Compiler #1) C++
x86-64 gcc 11.1
-std=c++20 
123
<Compilation failed>

# For more information see the output window
x86-64 gcc 11.1 - cached
Output of x86-64 gcc 11.1 (Compiler #1)
<source>: In substitution of 'template<auto Lambda> void f(decltype (Lambda))
[with auto Lambda = <missing>]':
<source>:17:6:   required from here
<source>:7:33: internal compiler error: in convert_nontype_argument, at
cp/pt.c:7652
    7 | template<auto Lambda = []{ g(1);} > void f(decltype(Lambda) x = {}) {
      |                                 ^
0x1780bf9 internal_error(char const*, ...)
        ???:0
0x677e40 fancy_abort(char const*, int, char const*)
        ???:0
0x7f3b4b fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0x68eda2 build_new_function_call(tree_node*, vec<tree_node*, va_gc,
vl_embed>**, int)
        ???:0
0x8070f0 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0x7c0cab c_parse_file()
        ???:0
0x892aa2 c_common_parse_file()
        ???:0
////////////////////
Compiler Explorer link: https://godbolt.org/z/Evcd7oaz5
////////////////////

Interestingly, if I comment out the definition of `a`, it compiles and runs
properly.

And if I comment out either of the last two calls to f(), it compiles and runs
properly.  Whether or not f<a>(); is commented out.

Reply via email to