https://gcc.gnu.org/bugzilla/show_bug.cgi?id=114495
Bug ID: 114495
Summary: Capture error in lambda fold
Product: gcc
Version: 13.2.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: andipeer at gmx dot net
Target Milestone: ---
The following code
#include <utility>
template <typename... Args>
void func(Args... args)
{
auto f = [&]<std::size_t... Indices>(std::index_sequence<Indices...>,
Args... args) {
auto f2 = [&](auto, auto) { };
(f2(Indices, args), ...);
};
f(std::make_index_sequence<sizeof...(args)>(),
std::forward<Args>(args)...);
}
int main()
{
func(3);
return 1;
}
is accepted by Clang and MSVC, but fails on GCC with
error: 'args#0' is not captured
(f2(Indices, args), ...);
It however compiles when changing the signature of the lambda `f` to use `auto`
instead of `Args` for the second parameter:
auto f = [&]<std::size_t... Indices>(std::index_sequence<Indices...>, auto...
args)
Online demo: https://gcc.godbolt.org/z/TjexTjhnc