<html><head><meta http-equiv="Content-Type" content="text/html charset=utf-8"></head><body style="word-wrap: break-word; -webkit-nbsp-mode: space; -webkit-line-break: after-white-space;" class=""><br class=""><div><blockquote type="cite" class=""><div class="">On May 26, 2016, at 4:55 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" class="">dexonsmith@apple.com</a>> wrote:</div><br class="Apple-interchange-newline"><div class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br class="Apple-interchange-newline">On 2016-May-26, at 16:16, Akira Hatanaka <<a href="mailto:ahatanak@gmail.com" class="">ahatanak@gmail.com</a>> wrote:<br class=""><br class="">On Thu, May 26, 2016 at 3:58 PM, Duncan P. N. Exon Smith <<a href="mailto:dexonsmith@apple.com" class="">dexonsmith@apple.com</a>> wrote:<br class=""><br class=""><blockquote type="cite" class="">On 2016-May-25, at 16:41, Hal Finkel via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class=""><br class=""><br class="">From: "James Dennett via cfe-dev" <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>><br class="">To: "Akira Hatanaka" <<a href="mailto:ahatanak@gmail.com" class="">ahatanak@gmail.com</a>><br class="">Cc: "Richard Smith" <<a href="mailto:richard@metafoo.co.uk" class="">richard@metafoo.co.uk</a>>, "Clang Dev" <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>><br class="">Sent: Wednesday, May 25, 2016 6:37:46 PM<br class="">Subject: Re: [cfe-dev] c++ question: can lambda be used in VLA?<br class=""><br class="">On Wed, May 25, 2016 at 4:19 PM, Akira Hatanaka <<a href="mailto:ahatanak@gmail.com" class="">ahatanak@gmail.com</a>> wrote:<br class="">On Tue, May 24, 2016 at 7:11 PM, James Dennett <<a href="mailto:james.dennett@gmail.com" class="">james.dennett@gmail.com</a>> wrote:<br class="">On Tue, May 24, 2016 at 6:25 PM, Akira Hatanaka via cfe-dev <<a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a>> wrote:<br class="">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?<br class=""><br class="">FYI, this isn't something that I made up. It was in a code a user wrote.<br class=""><br class=""><br class="">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.<br class=""><br class=""><br class="">Yes, the c++ standard gives a list of subexpressions that are not allowed in constant expressions and lambda expression is one of them.<br class=""><br class="">This doesn't seem to apply to C99's extension for variable length arrays because array sizes are not required to be constant expressions.<br class=""><br class=""><br class="">I was replying to you saying that you were "asking whether it was valid in C++", and whether "it's not covered by the standard".<br class=""><br class="">C99 doesn't have lambdas, so it doesn't allow this. C++ doesn't have VLAs, so it doesn't allow it.<br class=""><br class="">The de facto language accepted by Clang doesn't accept it, as you already noted.<br class=""><br class="">There's no specification that tells us what the "right thing to do" is here. We could extend Clang to support this non-standard combination of C99 with C++11, and it might even make it a little more consistent, but if it adds any implementation complexity then it may not be worthwhile to support a corner case that's not allowed by any language standard.<br class="">What did the most recent wording for C++ ARBs say about this issue?<br class=""></blockquote><br class="">The latest version I could find is here:<br class=""><a href="http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3820.html#Introduction" class="">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3820.html#Introduction</a><br class=""><br class="">The changes to 8.3.4 Arrays [dcl.array] change the argument from a constant-expression_opt to an expression_opt:<br class="">http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2013/n3820.html#dcl.array<br class=""><br class="">I think the Array TS was killed in Jacksonville due to lack of interest, but the interaction between these features seems straightforward to me. When the C++ language extension for VLAs is turned on, we shouldn't treat the array argument as a constant-expression. This effectively allows lambdas in array bounds.<br class=""><br class="">Akira, what does the patch for this look like?<br class=""><br class=""><br class="">My first patch just replaced the call to ParseConstantExpresssion at ParseDecl.cpp:6106 with ParseExpression. I didn't see the error message about lambda after applying the patch. It also caused clang to accept expressions like this, if I remember correctly:<br class=""><br class="">char a[1,2];<span class="Apple-converted-space"> </span><br class=""></blockquote><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">Hmm. That would merit a warning. IMO, -Wcomma should fire on every</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">use of the built-in comma operator that's not in the "increment"</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><span style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px; float: none; display: inline !important;" class="">statement of a for loop... I'm not sure if others agree though.</span><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""></div></blockquote><div><br class=""></div><div>I’m curious what that would look like on a large codebase. It sounds good to me, but potentially very noisy and perhaps a step too far in the direction of style enforcement rather than bug finding.</div><div><br class=""></div><div>A case I’d like to make sure gets caught is:</div><div><br class=""></div><div>int foo();</div><div>int bar();</div><div>...</div><div>a = foo(), (void)bar();</div><div><br class=""></div><div>There’s no warning or error for this code. However, change the assignment to a “return” and it’s a hard error. Precedence is a pain.</div><div><br class=""></div><div>The real issue is the far more nefarious:</div><div>a = foo(), bar();</div><div><br class=""></div><div>It’s going to be pretty darn rare to see that and the actual results being what was intended by the author.</div><div><br class=""></div><div><br class=""></div><blockquote type="cite" class=""><div class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><br style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" style="font-family: Helvetica; font-size: 12px; font-style: normal; font-variant-caps: normal; font-weight: normal; letter-spacing: normal; orphans: auto; text-align: start; text-indent: 0px; text-transform: none; white-space: normal; widows: auto; word-spacing: 0px; -webkit-text-stroke-width: 0px;" class=""><blockquote type="cite" class=""><br class="">-Hal<br class=""><br class="">-- James<br class=""><br class="">_______________________________________________<br class="">cfe-dev mailing list<br class=""><a href="mailto:cfe-dev@lists.llvm.org" class="">cfe-dev@lists.llvm.org</a><br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev<br class=""><br class=""><br class=""><br class="">--<br class="">Hal Finkel<br class="">Assistant Computational Scientist<br class="">Leadership Computing Facility<br class="">Argonne National Laboratory<br class="">_______________________________________________<br class="">cfe-dev mailing list<br class="">cfe-dev@lists.llvm.org<br class="">http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev</blockquote></blockquote></div></blockquote></div><br class=""></body></html>