https://gcc.gnu.org/bugzilla/show_bug.cgi?id=90623
Bug ID: 90623
Summary: compilation error with fold expression and parameter
pack
Product: gcc
Version: 9.1.0
Status: UNCONFIRMED
Severity: normal
Priority: P3
Component: c++
Assignee: unassigned at gcc dot gnu.org
Reporter: remi.louvot at gmail dot com
Target Milestone: ---
This is (literally) a text book example of lambda expression with c++17, it
compiles fine with gcc8 and latest clang, but gcc9 throws an error around the
fold expression in which each expression takes the whole pack as third argument
source>: In instantiation of 'main()::<lambda(auto:4 ...)> [with auto:4 = {int,
int, int}]':
<source>:17:56: required from here
<source>:11:36: error: redeclaration of 'const int xs#1'
11 | (call_cart(f, xs, xs... ), ...);
//compiled with -std=c++17
#include <iostream>
int main(){
auto call_cart{[=](auto f, auto x, auto...rest) {
(((x < rest) ? f(x, rest) : (void) 0), ...);
}};
auto cartesian{[=](auto...xs) {
return [=](auto f) {
(call_cart(f, xs, xs... ), ...); // ok with gcc8 // error with gcc9
// other version without fold expression // same problem
// (void)std::initializer_list<int>{((void)call_cart(f,xs,xs...),0)...};
};
}};
constexpr auto print_cart{cartesian(1, 2, 3)};
static_assert((print_cart([](int x, int y)constexpr{}),true));
print_cart([](int x, int y) { std::cout << x << "," << y << std::endl; });
}