https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97938
Bug ID: 97938 Summary: g++ crash when inferring type of auto parameter pack in lambda capture Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: elel at 3wh dot net Target Milestone: --- The following test case: #include <iostream> #include <tuple> template <typename... Args> int print_args(Args&&... args) { std::cout << (args << ...); return sizeof...(args); } template <typename T1, typename T2> auto fwd(const T1& t1, const T2& t2) { return std::apply([&t2] (auto&&... ts1) { return std::apply([...ts1 = std::forward<decltype(ts1)>(ts1)] (auto&&... ts2) { return print_args(ts1..., std::forward<decltype(ts2)>(ts2)...); }, t2); }, t1); } int main() { auto t1 = std::make_tuple(int{1}, float{2}); auto t2 = std::make_tuple(float{3}, int{4}); return fwd(t1, t2); } Compiled as: g++ -std=c++20 -g -O2 gcc_crash.cpp Crashes g++ with the following message: gcc_crash.cpp: In instantiation of ‘fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)> [with auto:11 = {const int&, const float&}]’: /usr/include/c++/10.2.0/type_traits:2506:26: required by substitution of ‘template<class _Fn, class ... _Args> static std::__result_of_success<decltype (declval<_Fn>()((declval<_Args>)()...)), std::__invoke_other> std::__result_of_other_impl::_S_test(int) [with _Fn = fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>; _Args = {const int&, const float&}]’ /usr/include/c++/10.2.0/type_traits:2517:55: required from ‘struct std::__result_of_impl<false, false, fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>’ /usr/include/c++/10.2.0/type_traits:138:12: recursively required by substitution of ‘template<class _Result, class _Ret> struct std::__is_invocable_impl<_Result, _Ret, true, std::__void_t<typename _CTp::type> > [with _Result = std::__invoke_result<fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>; _Ret = void]’ /usr/include/c++/10.2.0/type_traits:138:12: required from ‘struct std::__and_<std::__is_invocable_impl<std::__invoke_result<fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>, void, true, void>, std::__call_is_nothrow<std::__invoke_result<fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>, fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&> >’ /usr/include/c++/10.2.0/type_traits:2979:12: required from ‘struct std::is_nothrow_invocable<fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const int&, const float&>’ /usr/include/c++/10.2.0/tuple:1715:37: required from ‘constexpr const bool std::__unpack_std_tuple<template<class _Fn, class ... _ArgTypes> struct std::is_nothrow_invocable, fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>, const std::tuple<int, float>&>’ /usr/include/c++/10.2.0/tuple:1730:14: required from ‘constexpr decltype(auto) std::apply(_Fn&&, _Tuple&&) [with _Fn = fwd<std::tuple<int, float>, std::tuple<float, int> >::<lambda(auto:11&& ...)>; _Tuple = const std::tuple<int, float>&]’ gcc_crash.cpp:12:20: required from ‘auto fwd(const T1&, const T2&) [with T1 = std::tuple<int, float>; T2 = std::tuple<float, int>]’ gcc_crash.cpp:22:20: required from here gcc_crash.cpp:13:23: internal compiler error: Segmentation fault 13 | return std::apply([...ts1 = std::forward<decltype(ts1)>(ts1)] (auto&&... ts2) { | ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 14 | return print_args(ts1..., std::forward<decltype(ts2)>(ts2)...); | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 15 | }, t2); | ~ Please submit a full bug report, with preprocessed source if appropriate. In other scenarios (not the minimal test case above) the same bug triggers the message: internal compiler error: in cxx_incomplete_type_diagnostic, at cp/typeck2.c:584