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

            Bug ID: 124595
           Summary: ICE when using named capture-by-value in lambda
           Product: gcc
           Version: 16.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: apostolostpiperis at gmail dot com
  Target Milestone: ---

Code snippet reproducing the bug:

```
constexpr auto id = [](int n) { return n; };

constexpr auto noop(auto f) {
  return [fc = f]<typename Arg>
    requires (sizeof(Arg) != sizeof(fc))
  (Arg) { return 42; };
}

static_assert(noop(id)(4) == 42);
```

Issue encountered on GCC 16.0 with the following options:
  * Target: `x86_64-linux-gnu`

  * Compiler build options: `--build=x86_64-linux-gnu --host=x86_64-linux-gnu
--target=x86_64-linux-gnu --disable-bootstrap --enable-multiarch --with-abi=m64
--with-multilib-list=m32,m64,mx32 --enable-multilib --enable-clocale=gnu
--enable-ld=yes --enable-gold=yes --enable-libstdcxx-time=yes
--enable-linker-build-id --enable-lto --enable-plugins --enable-threads=posix`

  * Snippet compilation flags: `-masm=intel -mtune=generic -march=x86-64 -g
-std=c++20 -fdiagnostics-color=always -fno-verbose-asm`

Error message produced by the compiler is as follows:
<source>: In substitution of 'template<class Arg>  requires  sizeof (Arg) !=
sizeof noop::._anon_1::operator()::fc noop<<lambda(int)>
>(<lambda(int)>)::<lambda(Arg)> [with Arg = int]':
<source>:9:23:   required from here
    9 | static_assert(noop(id)(4) == 42);
      |               ~~~~~~~~^~~
<source>:4:17: internal compiler error: in tsubst_decl, at cp/pt.cc:16213
    4 |   return [fc = f]<typename Arg>
      |                 ^
0x2967ad8 diagnostics::context::diagnostic_impl(rich_location*,
diagnostics::metadata const*, diagnostics::option_id, char const*,
__va_list_tag (*) [1], diagnostics::kind)
        ???:0
0x295c71b internal_error(char const*, ...)
        ???:0
0xb22c1c fancy_abort(char const*, int, char const*)
        ???:0
0xbb7b28 constraints_satisfied_p(tree_node*, tree_node*)
        ???:0
0xdd4981 fn_type_unification(tree_node*, tree_node*, tree_node*, tree_node*
const*, unsigned int, tree_node*, unification_kind_t, int, conversion**, bool,
bool)
        ???:0
0xb5fa82 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
        ???:0
0xe0d256 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
        ???:0
0xd6f323 c_parse_file()
        ???:0
0xef98c9 c_common_parse_file()
        ???:0
cc1plus -quiet -imultiarch x86_64-linux-gnu -iprefix
/cefs/12/1225dba6a8e84200e8514484_gcc-trunk-20260320/bin/../lib/gcc/x86_64-linux-gnu/16.0.1/
-D_GNU_SOURCE <source> -quiet -dumpdir /app/ -dumpbase output.cpp -dumpbase-ext
.cpp -masm=intel -mtune=generic -march=x86-64 -g -std=c++20
-fdiagnostics-color=always -fno-verbose-asm -o /app/output.s

Issue was reproduced in Compiler Explorer, please don't hesitate to request
another backtrace (originating from a different machine) of me if needed.

Reply via email to