[cfe-dev] c++ question: can lambda be used in VLA?

Akira Hatanaka via cfe-dev cfe-dev at lists.llvm.org
Wed May 11 15:37:44 PDT 2016


clang currently errors out if I use lambda to compute the size of an array:

$ cat t.cpp
int foo3();

void foo() {
  unsigned char a1[([](int a) {return a; })(1)];
}

$ clang++ t.cpp -c -std=c++11

 *error: **a lambda expression may not appear inside of a constant
expression*

  unsigned char a1[([](int a) { return a; })(1)];


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?
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160511/489eac2b/attachment.html>


More information about the cfe-dev mailing list