[PATCH] D24639: [Sema] Warn when returning a lambda that captures a local variable by reference
Alexey Bataev via cfe-commits
cfe-commits at lists.llvm.org
Thu Sep 15 23:23:40 PDT 2016
ABataev added a subscriber: ABataev.
================
Comment at: lib/Sema/SemaChecking.cpp:6588
@@ -6587,2 +6587,3 @@
stackE = EvalAddr(RetValExp, refVars, /*ParentDecl=*/nullptr);
+
} else if (lhsType->isReferenceType()) {
----------------
Remove empty line
================
Comment at: lib/Sema/SemaChecking.cpp:6591
@@ -6589,1 +6590,3 @@
stackE = EvalVal(RetValExp, refVars, /*ParentDecl=*/nullptr);
+
+ } else if (CXXRecordDecl *LambdaDecl = lhsType->getAsCXXRecordDecl()) {
----------------
Remove empty line
================
Comment at: lib/Sema/SemaChecking.cpp:6592
@@ +6591,3 @@
+
+ } else if (CXXRecordDecl *LambdaDecl = lhsType->getAsCXXRecordDecl()) {
+ if (LambdaDecl->isLambda())
----------------
auto *LambdaDecl
================
Comment at: lib/Sema/SemaChecking.cpp:6709
@@ -6699,3 +6708,3 @@
- if (const VarDecl *V = dyn_cast<VarDecl>(DR->getDecl()))
+ if (const VarDecl *V = dyn_cast<VarDecl>(DR->getDecl())) {
// If this is a reference variable, follow through to the expression that
----------------
const auto *V
================
Comment at: lib/Sema/SemaChecking.cpp:6993-6994
@@ +6992,4 @@
+
+ auto init = Lambda->capture_init_begin();
+ auto cap = Lambda->capture_begin(), cap_end = Lambda->capture_end();
+
----------------
auto Init, auto Cap. Local vars must start from capital letters
================
Comment at: lib/Sema/SemaChecking.cpp:6996
@@ +6995,3 @@
+
+ for (; cap != cap_end; ++cap, ++init) {
+ if (!cap->capturesVariable())
----------------
Maybe it is better to use ranged-based loop, like `for (auto &Cap : Lambda->captures())`
https://reviews.llvm.org/D24639
More information about the cfe-commits
mailing list