<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.<br><div><div class="gmail_extra"><br><div class="gmail_quote">On Tue, May 24, 2016 at 5:37 PM, Richard Smith <span dir="ltr"><<a href="mailto:richard@metafoo.co.uk" target="_blank">richard@metafoo.co.uk</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">Sure, yes, that's one way of allowing this, but why do you want to? What would justify the added complexity of allowing this special case?<br><div class="gmail_extra"><br><div class="gmail_quote"><div><div class="h5">On Tue, May 24, 2016 at 2:47 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></div></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><div class="h5"><div dir="ltr"><div>I believe this is not allowed in standard c++ but is allowed as a C99 extension. </div><div><br></div><div>I can silence the error if I replace the call to ParseConstantExpression at ParseDecl.cpp:6098 with ParseExpression, but it also causes other regression tests to fail.<br></div><div><br></div><div>I also tried adding a flag IsArrayBound to ExpressionEvaluationContextRecord, which indicates the expression is used for an array bound. The value of the flag is checked In Sema::PopExpressionEvaluationContext and diagnostics for lambda expression are not emitted if the flag is true.<div><div><div><br></div><div><div class="gmail_extra"><div class="gmail_quote">On Wed, May 11, 2016 at 3:37 PM, Akira Hatanaka <span dir="ltr"><<a href="mailto:ahatanak@gmail.com" target="_blank">ahatanak@gmail.com</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"><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>
</blockquote></div><br></div></div></div></div></div></div>
<br></div></div>_______________________________________________<br>
cfe-dev mailing list<br>
<a href="mailto:cfe-dev@lists.llvm.org" target="_blank">cfe-dev@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</a><br>
<br></blockquote></div><br></div></div>
</blockquote></div><br></div></div></div></div>