https://gcc.gnu.org/bugzilla/show_bug.cgi?id=123408
Bug ID: 123408
Summary: ICE in tsubst_lambda_expr with generic lambda
expansion used in template alias (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 63223
--> https://gcc.gnu.org/bugzilla/attachment.cgi?id=63223&action=edit
report-bug file
The Code:
```
template <typename> constexpr int zero = 0;
template <auto> using int_alias = int;
template <typename Arg>
using inner = int_alias<[]<typename> { return 0; }.template operator()<Arg>()>;
template <typename Arg>
constexpr int outer =
[]<typename> { return zero<inner<Arg>>; }.template operator()<Arg>();
int main() { auto a = outer<int>; }
```
The ICE:
```
test.cpp: In instantiation of ‘<lambda()> [with <template-parameter-1-1> =
int]’:
test.cpp:9:71: required from ‘constexpr const int outer<int>’
9 | []<typename> { return zero<inner<Arg>>; }.template
operator()<Arg>();
|
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^~
test.cpp:11:23: required from here
11 | int main() { auto a = outer<int>; }
| ^~~~~~~~~~
test.cpp:5:25: internal compiler error: Segmentation fault
5 | using inner = int_alias<[]<typename> { return 0; }.template
operator()<Arg>()>;
| ^~~~~~~~~~~~~~~~~~~~~~~~~~
0x26ed011 diagnostic_context::diagnostic_impl(rich_location*,
diagnostic_metadata const*, diagnostic_option_id, char const*, __va_list_tag
(*) [1], diagnostic_t)
???:0
0x2747118 internal_error(char const*, ...)
???:0
0x90c608 template_parms_to_args(tree_node*)
???:0
0x925e9d tsubst_lambda_expr(tree_node*, tree_node*, int, tree_node*)
???:0
0x91f8d7 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x915c32 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x915dd7 tsubst(tree_node*, tree_node*, int, tree_node*)
???:0
0x91f8d7 tsubst_template_args(tree_node*, tree_node*, int, tree_node*)
???:0
0x928e0d instantiate_decl(tree_node*, bool, bool)
???:0
0x7b7912 maybe_instantiate_decl(tree_node*)
???:0
0x7c9357 mark_used(tree_node*, int)
???:0
0x742df5 build_new_method_call(tree_node*, tree_node*, vec<tree_node*, va_gc,
vl_embed>**, tree_node*, int, tree_node**, int)
???:0
0x946730 finish_call_expr(tree_node*, vec<tree_node*, va_gc, vl_embed>**, bool,
bool, int)
???:0
0x928e0d instantiate_decl(tree_node*, bool, bool)
???:0
0x7c9259 mark_used(tree_node*, int)
???:0
0xa22ff0 c_common_parse_file()
???:0
```
Reproducable on godbolt with 14.1.0 - 15.2.0 and trunk(16.0.0), but works on
clang and msvc:
https://godbolt.org/z/xK9h7zGhG
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 20251112 (GCC)
```
Output produced with: g++ --std=c++20 -freport-bug test.cpp is attatched