<div dir="ltr"><div class="gmail_extra"><div class="gmail_quote">On Tue, May 24, 2016 at 7:11 PM, James Dennett <span dir="ltr"><<a href="mailto:james.dennett@gmail.com" target="_blank">james.dennett@gmail.com</a>></span> wrote:<br></div><div class="gmail_quote"><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><span class="">On Tue, May 24, 2016 at 6:25 PM, Akira Hatanaka via cfe-dev <span dir="ltr"><<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr">I wasn't requesting that clang accept lambda expressions used for array bounds but was asking whether it was valid in c++. Is this something that is open to interpretation because it's not covered by the standard?<div><br></div><div>FYI, this isn't something that I made up. It was in a code a user wrote.<div><div><br></div></div></div></div></blockquote><div><br></div></span><div>It's covered by the standard, and as Clang's error message says, lambdas are not allowed in constant expressions in C++11 or C++14.</div><div><br></div></div></div></div></blockquote><div><br></div><div>Yes, the c++ standard gives a list of subexpressions that are not allowed in constant expressions and lambda expression is one of them.</div><div><br></div><div>This doesn't seem to apply to C99's extension for variable length arrays because array sizes are not required to be constant expressions.</div><div><br></div><div>For example, if we declare the following variable length arrays,</div><div><br></div><div>(1) unsigned char a1[foo1()];</div><div>(2) unsigned char a1[dynamic_cast<S*>(s) + 3];</div><div> <br></div><div>clang compiles (1) and (2) without any warnings or errors (unless -pedantic is used). However, if we use lambda for the array size, clang complains that lambda cannot be used in constant expressions:</div><div><br></div><div><div>(3) unsigned char a1[([](int a){ return a; })(4)];</div></div><div><br></div><blockquote class="gmail_quote" style="margin:0px 0px 0px 0.8ex;border-left-width:1px;border-left-style:solid;border-left-color:rgb(204,204,204);padding-left:1ex"><div dir="ltr"><div class="gmail_extra"><div class="gmail_quote"><div></div><div><a href="https://isocpp.org/files/papers/N4487.pdf" target="_blank">https://isocpp.org/files/papers/N4487.pdf</a> proposed constexpr lambdas for a future standard, and was accepted by EWG; draft wording is in <a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0170r1.pdf" target="_blank">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/p0170r1.pdf</a></div><span class=""><font color="#888888"><div><br></div><div>-- James</div><div><br></div><div><br></div></font></span></div></div></div>
</blockquote></div><br></div></div>