Compile with g++.exe -m64 -std=c++17
and any optimization level, and run:
#include <iostream>
int main() {
const auto L1 = [&](){};
std::cout << sizeof(L1) << std::endl;
const auto L2 = [&](){L1;};
std::cout << sizeof(L2) << std::endl;
const auto L3 = [&](){L1, L2;};
std::cout << sizeof(L3) << std::endl;
const auto L4 = [&](){L1, L2, L3;};
std::cout << sizeof(L4) << std::endl;
}
The output is 1,8,16,24
, which means that L2 contains 1 reference, L3 contains 2 and L4 contains 3.
However, given the same function "[&](){L1, L2;}
in main()
", the value of &L1 - &L2
should be fixed, and to use L1
with a pointer to L2
, there's direct addressing in x86 [rbx+const]
assuming rbx=&L2
. Why does GCC still choose to include every reference in the lambda?