summaryrefslogtreecommitdiffstats
path: root/clang/lib/Sema/SemaLambda.cpp
diff options
context:
space:
mode:
authorAlexey Bataev <a.bataev@hotmail.com>2016-11-11 12:36:20 +0000
committerAlexey Bataev <a.bataev@hotmail.com>2016-11-11 12:36:20 +0000
commit31939e39db2ca3f26868f1f961be0e6c9026a45c (patch)
treea0bd1889030cc7429def9f841ae3aca8002d998b /clang/lib/Sema/SemaLambda.cpp
parentcdfdff0b182a8a4a06ba99d7410f0d129b743a45 (diff)
downloadbcm5719-llvm-31939e39db2ca3f26868f1f961be0e6c9026a45c.tar.gz
bcm5719-llvm-31939e39db2ca3f26868f1f961be0e6c9026a45c.zip
Fix for PR28523: unexpected compilation error.
Clang emits error message for the following code: ``` template <class F> void parallel_loop(F &&f) { f(0); } int main() { int x; parallel_loop([&](auto y) { { x = y; }; }); } ``` $ clang++ --std=gnu++14 clang_test.cc -o clang_test clang_test.cc:9:7: error: reference to local variable 'x' declared in enclosing function 'main' x = y; ^ clang_test.cc:2:48: note: in instantiation of function template specialization 'main()::(anonymous class)::operator()<int>' requested here template <class F> void parallel_loop(F &&f) { f(0); } ^ clang_test.cc:6:3: note: in instantiation of function template specialization 'parallel_loop<(lambda at clang_test.cc:6:17)>' requested here parallel_loop([&](auto y) { ^ clang_test.cc:5:7: note: 'x' declared here int x; ^ 1 error generated. Patch fixes this issue. llvm-svn: 286584
Diffstat (limited to 'clang/lib/Sema/SemaLambda.cpp')
-rw-r--r--clang/lib/Sema/SemaLambda.cpp11
1 files changed, 7 insertions, 4 deletions
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp
index da4ba8b2a26..fb3ac072f1e 100644
--- a/clang/lib/Sema/SemaLambda.cpp
+++ b/clang/lib/Sema/SemaLambda.cpp
@@ -66,17 +66,20 @@ getStackIndexOfNearestEnclosingCaptureReadyLambda(
// Label failure to capture.
const Optional<unsigned> NoLambdaIsCaptureReady;
+ // Ignore all inner captured regions.
+ unsigned CurScopeIndex = FunctionScopes.size() - 1;
+ while (CurScopeIndex > 0 && isa<clang::sema::CapturedRegionScopeInfo>(
+ FunctionScopes[CurScopeIndex]))
+ --CurScopeIndex;
assert(
- isa<clang::sema::LambdaScopeInfo>(
- FunctionScopes[FunctionScopes.size() - 1]) &&
+ isa<clang::sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex]) &&
"The function on the top of sema's function-info stack must be a lambda");
-
+
// If VarToCapture is null, we are attempting to capture 'this'.
const bool IsCapturingThis = !VarToCapture;
const bool IsCapturingVariable = !IsCapturingThis;
// Start with the current lambda at the top of the stack (highest index).
- unsigned CurScopeIndex = FunctionScopes.size() - 1;
DeclContext *EnclosingDC =
cast<sema::LambdaScopeInfo>(FunctionScopes[CurScopeIndex])->CallOperator;
OpenPOWER on IntegriCloud