https://gcc.gnu.org/bugzilla/show_bug.cgi?id=107955
Bug ID: 107955 Summary: ICE: trying to capture ‘ARGS#0’ in instantiation of generic lambda Product: gcc Version: 12.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: onebit74 at gmail dot com Target Milestone: --- The code is valid If you comment out the if, it compiles. If you comment out the branches in the if, it compiles as well. But somehow putting them together gives ICE. #include <functional> template<typename F> struct agg_p { F f; void _parse(auto...ARGS){ [&](auto...P_ARGS){ using result = std::invoke_result_t<F,decltype(ARGS)...,decltype(P_ARGS)...>; if constexpr(!std::same_as<result, void>){ f(ARGS...,P_ARGS...); }else{ f(ARGS...,P_ARGS...); } }(1); } }; int main(){ auto add = [](auto a, auto b){return a+b;}; auto agg = agg_p(add); int i; agg._parse(i); }