structure binding followed by a lambda capture creates a clang compilation error

Viewed 203

When using c++17 structure bindings and used these variables to be captured by a lambda function, clang fails to compile but it does work for MSVC and GCC. Here is the code (on godbolt):

std::tuple<int, double, long> f() { return { 1, 2., 3 }; }
auto [a,b,c] = f();
[a, &b, other = c]() {
    std::cout << a << b << other << std::endl;
}();

Clang returns an error for a and b: error: 'a' in capture list does not name a variable. I am not sure this is a valid code though. Can someone tell which compiler does things right?

Thank you

0 Answers
Related