[PATCH] [C++11] Support for capturing of variable length arrays in lambda expression.
Richard Smith
richard at metafoo.co.uk
Mon Aug 25 11:59:18 PDT 2014
================
Comment at: include/clang/AST/LambdaCapture.h:67
@@ -66,3 +66,3 @@
/// \brief Determine the kind of capture.
LambdaCaptureKind getCaptureKind() const;
----------------
Have you considered adding an LCK_ value for VLA capture? Calling it `LCK_ByCopy` doesn't seem quite right.
================
Comment at: lib/AST/Decl.cpp:3303-3305
@@ -3292,4 +3302,5 @@
void FieldDecl::setBitWidth(Expr *Width) {
+ assert(isBitField() && "not a bitfield");
assert(!InitializerOrBitWidth.getPointer() && !hasInClassInitializer() &&
- "bit width or initializer already set");
+ "bit width, initializer or captured type already set");
InitializerOrBitWidth.setPointer(Width);
----------------
This pair of asserts doesn't make sense. A field can only be a bit-field if it has a bit-width, but you're asserting that it's a bit-field *and* has no bit-width.
This is only passing the tests because `setBitWidth` is never called. Please remove the assert you added here. (I suspect this function is called by lldb or similar, otherwise I'd just suggest removing it entirely.)
================
Comment at: lib/AST/Decl.cpp:3317
@@ +3316,3 @@
+ return getDeclContext()->isRecord() && getParent()->isLambda() &&
+ getInClassInitStyle() == ICIS_NoInit &&
+ InitializerOrBitWidth.getPointer();
----------------
Is this check necessary? You can't have an in-class initializer in a lambda.
================
Comment at: lib/AST/Decl.cpp:3549-3551
@@ +3548,5 @@
+bool RecordDecl::isLambda() const {
+ if (auto RD = dyn_cast<CXXRecordDecl>(this)) {
+ return RD->isLambda();
+ }
+ return false;
----------------
No braces here, please.
================
Comment at: lib/AST/StmtPrinter.cpp:1711-1712
@@ -1710,2 +1710,4 @@
++C) {
+ if (C->capturesVLAType())
+ continue;
if (NeedComma)
----------------
Is this possible? I would have expected VLA captures to always be implicit.
================
Comment at: lib/AST/StmtProfile.cpp:1020-1021
@@ -1019,2 +1019,4 @@
C != CEnd; ++C) {
+ if (C->capturesVLAType())
+ continue;
ID.AddInteger(C->getCaptureKind());
----------------
Likewise.
================
Comment at: lib/Sema/SemaExpr.cpp:11668
@@ -11667,2 +11667,3 @@
// Prohibit variably-modified types; they're difficult to deal with.
+ if (Var->getType()->isVariablyModifiedType() && IsBlock) {
----------------
Update this comment: "Prohibit variably-modified types in blocks; ..." maybe?
================
Comment at: lib/Sema/SemaExpr.cpp:12075-12082
@@ -12077,2 +12074,10 @@
+static bool isVLATypeIsCaptured(LambdaScopeInfo *LSI,
+ const VariableArrayType *VAT) {
+ for (auto *FD : LSI->Lambda->fields()) {
+ if (FD->hasCapturedVLAType() && FD->getCapturedVLAType() == VAT)
+ return true;
+ }
+ return false;
+}
----------------
Please make this a member of `CapturingScopeInfo`. Also, drop one of the `Is`s from its name.
http://reviews.llvm.org/D4368
More information about the cfe-commits
mailing list