<div dir="ltr"><div>clang currently errors out if I use lambda to compute the size of an array:</div><div><br></div><div>$ cat t.cpp</div>int foo3();<div><br></div><div><div>void foo() {</div><div> unsigned char a1[([](int a) {return a; })(1)];</div><div>}</div></div><div><br></div><div>$ clang++ t.cpp -c -std=c++11</div><div><br></div><div><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span><b> </b></span><span style="color:rgb(195,55,32)"><b>error: </b></span><span><b>a lambda expression may not appear inside of a constant expression</b></span></p>
<p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><span> unsigned char a1[([](int a) { return a; })(1)];</span></p><p style="margin:0px;font-size:11px;line-height:normal;font-family:Menlo"><br></p><p style="margin:0px;line-height:normal">I was wondering why this isn't allowed since clang supports VLA. If a1 is a VLA, the size of the array doesn't have to be a constant expression, so it seems that we should be able to use lambda in this example?</p></div></div>