#include <tuple>
#include <iostream>
int main(){
const auto [x, y] = [&]{
const int x = 42;
const int y = 815;
return std::tuple{x, y};
}();
[&x]{
int y = x;
std::cout << y << '\n';
}();
return 0;
}
Clang输出的错误信息:
:11:7: error: 'x' in capture list does not name a variable
[&x]{
^
:12:17: error: reference to local binding 'x' declared in enclosing function 'main'
int y = x;
^
:5:17: note: 'x' declared here
const auto [x, y] = [&]{