Please consider this code:
#include <iostream>
#include <algorithm>
#include <numeric>
int main()
{
volatile auto width = uint64_t(5);
alignas(16)
char runtime[width]; std::iota(runtime,runtime+width,'1');
auto out = [](auto& curr) { std::cout << curr; };
auto capt_ref_to_runtime_bound_arr = [&runtime,width,out](auto &curr) {
std::for_each(runtime, runtime+width, out);
std::cout << " and width="
<< sizeof(runtime) / sizeof(*runtime)
<< '\n';
};
// clang code crashes even if below is commented out.
// std::for_each(runtime,runtime+width,capt_ref_to_runtime_bound_arr);
}
about the [&runtime] capture
GCC seems to decay
int(&)[width]tochar *(see wandbox below)clang just crashes into a red text chunk (see wandbox below)
Later, I ran to N3639, it says some features are cut off (e.g. sizeof in the demo above is actually ill-form). But why don't compilers explain these cut offs to me? And if the standard allow this kind of capture, how does they define it?
ASM: godbolt.org/g/ptRRRp
GCC 7.2 -O1: wandbox.org/permlink/30muSDtbxZYeGV2p
clang 5.0 -O1: wandbox.org/permlink/yvvRhBLFXzzxmihi