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

Akira Hatanaka via cfe-dev cfe-dev at lists.llvm.org
Tue May 24 18:25:01 PDT 2016


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?

FYI, this isn't something that I made up. It was in a code a user wrote.

On Tue, May 24, 2016 at 5:37 PM, Richard Smith <richard at metafoo.co.uk>
wrote:

> 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?
>
> On Tue, May 24, 2016 at 2:47 PM, Akira Hatanaka via cfe-dev <
> cfe-dev at lists.llvm.org> wrote:
>
>> I believe this is not allowed in standard c++ but is allowed as a C99
>> extension.
>>
>> 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.
>>
>> 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.
>>
>> On Wed, May 11, 2016 at 3:37 PM, Akira Hatanaka <ahatanak at gmail.com>
>> wrote:
>>
>>> 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?
>>>
>>
>>
>> _______________________________________________
>> cfe-dev mailing list
>> cfe-dev at lists.llvm.org
>> http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-dev
>>
>>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.llvm.org/pipermail/cfe-dev/attachments/20160524/617c0fff/attachment.html>


More information about the cfe-dev mailing list