[PATCH] D21187: Allow use of lambda expressions in array bounds
Akira Hatanaka via cfe-commits
cfe-commits at lists.llvm.org
Thu Jun 9 10:21:21 PDT 2016
ahatanak created this revision.
ahatanak added a subscriber: cfe-commits.
clang currently errors out when a lambda expression is used to compute the size of an array even though clang supports variable-length arrays as a C99 extension. For example,
$ cat vla1.cpp
```
int foo3();
struct S1 {
virtual ~S1();
};
struct S2 : S1 {
};
void foo(S1 *s1) {
unsigned char a1[([](int a) {return a; })(1)];
unsigned char a2[foo3()]; // This is OK.
unsigned char a3[!dynamic_cast<S2 *>(s1) + 1]; // This is OK.
}
```
$ clang++ vla1.cpp -c -std=c++11
vla1.cpp:11:21: error: a lambda expression may not appear inside of a constant expression
unsigned char a1[([](int a) {return a; })(1)];
^
1 error generated.
To handle VLAs in a more consistent way, this patch makes changes to allow lambda expressions to be used for array bounds if it is in a BlockContext.
http://reviews.llvm.org/D21187
Files:
include/clang/Parse/Parser.h
include/clang/Sema/Sema.h
lib/Parse/ParseDecl.cpp
lib/Parse/ParseExpr.cpp
lib/Sema/Sema.cpp
lib/Sema/SemaExpr.cpp
test/SemaCXX/lambda-expressions.cpp
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D21187.60193.patch
Type: text/x-patch
Size: 8299 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20160609/959b2ff5/attachment-0001.bin>
More information about the cfe-commits
mailing list