https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123700
Bug ID: 123700
Summary: ICE in tsubst_lambda_expr with generic lambdas in
template non-type parameter (C++20)
Product: gcc
Version: 15.2.1
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: mandelbrotuser at outlook dot de
Target Milestone: ---
Created attachment 63392
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63392&action=edit
report-bug file
Might be a duplicate of https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123408
The following minimal reproducible example results in an ICE:
```
template <typename> constexpr int zero = 0;
template <auto> struct Type;
int outer(auto) {
using inner = Type<[](auto) {}>;
return [](auto) { return zero<inner>; }(0);
}
int main() { outer(0); }
```
Compiling this example with g++ --std=c++20 test.cpp results in this ICE
(output with -freport-bug is also attached):
```
test.cpp: In instantiation of ‘outer<int>(int)::<lambda(auto:3)> [with auto:3 =
int]’:
test.cpp:6:42: required from ‘int outer(auto:1) [with auto:1 = int]’
6 | return [](auto) { return zero<inner>; }(0);
| ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~
test.cpp:9:19: required from here
9 | int main() { outer(0); }
| ~~~~~^~~
test.cpp:5:22: internal compiler error: Segmentation fault
5 | using inner = Type<[](auto) {}>;
| ^~~~~~~~~~~
0x26ed4d1 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
???:0
0x27475d8 internal_error(char const*, ...)
???:0
0x90c588 template_parms_to_args(tree_node*)
???:0
0x925e4d tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0x91f8b7 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x915c7b tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x91f8b7 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x928dcd instantiate_decl(tree_node*, bool, bool)
???:0
0x7b7712 maybe_instantiate_decl(tree_node*)
???:0
0x7c9157 mark_used(tree_node*, int)
???:0
0x754bb9 build_op_call(tree_node*, vec<tree_node*, va_gc, vl_embed>**, int)
???:0
0x946a36 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0x928dcd instantiate_decl(tree_node*, bool, bool)
???:0
0x92d2cb instantiate_pending_templates(int)
???:0
0x7eaa58 c_parse_final_cleanups()
???:0
0xa2318a c_common_parse_file()
???:0
```
Reproducible on Godbolt with 14.1.0 - 15.2.0 and trunk(16.0.1), but works on
clang and msvc:
https://godbolt.org/z/exWsGzrEf
g++ -v:
```
Using built-in specs.
COLLECT_GCC=g++
COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-pc-linux-gnu/15.2.1/lto-wrapper
Target: x86_64-pc-linux-gnu
Configured with: /build/gcc/src/gcc/configure
--enable-languages=ada,c,c++,d,fortran,go,lto,m2,objc,obj-c++,rust,cobol
--enable-bootstrap --prefix=/usr --libdir=/usr/lib --libexecdir=/usr/lib
--mandir=/usr/share/man --infodir=/usr/share/info
--with-bugurl=https://gitlab.archlinux.org/archlinux/packaging/packages/gcc/-/issues
--with-build-config=bootstrap-lto --with-linker-hash-style=gnu
--with-system-zlib --enable-__cxa_atexit --enable-cet=auto
--enable-checking=release --enable-clocale=gnu --enable-default-pie
--enable-default-ssp --enable-gnu-indirect-function --enable-gnu-unique-object
--enable-libstdcxx-backtrace --enable-link-serialization=1
--enable-linker-build-id --enable-lto --enable-multilib --enable-plugin
--enable-shared --enable-threads=posix --disable-libssp --disable-libstdcxx-pch
--disable-werror
Thread model: posix
Supported LTO compression algorithms: zlib zstd
gcc version 15.2.1 20260103 (GCC)
```