diff options
| author | Richard Trieu <rtrieu@google.com> | 2016-03-05 04:04:57 +0000 |
|---|---|---|
| committer | Richard Trieu <rtrieu@google.com> | 2016-03-05 04:04:57 +0000 |
| commit | 2334a30e15fcfff5607f88472647762b76432fa1 (patch) | |
| tree | de5551bd32281243959d811e36999c9f17bdad05 | |
| parent | c4572c2a854e19457c45e2e337692cb1cb11bcb9 (diff) | |
| download | bcm5719-llvm-2334a30e15fcfff5607f88472647762b76432fa1.tar.gz bcm5719-llvm-2334a30e15fcfff5607f88472647762b76432fa1.zip | |
Add null check to diagnostic path for lambda captures.
Previously, the failed capture of a variable in nested lambdas may crash when
the lambda pointer is null. Only give the note if a location can be retreived
from the lambda pointer.
llvm-svn: 262765
| -rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 5 | ||||
| -rw-r--r-- | clang/test/SemaCXX/lambda-expressions.cpp | 12 |
2 files changed, 15 insertions, 2 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index a90fda8bfce..4071acd9063 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13509,8 +13509,9 @@ bool Sema::tryCaptureVariable( Diag(ExprLoc, diag::err_lambda_impcap) << Var->getDeclName(); Diag(Var->getLocation(), diag::note_previous_decl) << Var->getDeclName(); - Diag(cast<LambdaScopeInfo>(CSI)->Lambda->getLocStart(), - diag::note_lambda_decl); + if (cast<LambdaScopeInfo>(CSI)->Lambda) + Diag(cast<LambdaScopeInfo>(CSI)->Lambda->getLocStart(), + diag::note_lambda_decl); // FIXME: If we error out because an outer lambda can not implicitly // capture a variable that an inner lambda explicitly captures, we // should have the inner lambda do the explicit capture - because diff --git a/clang/test/SemaCXX/lambda-expressions.cpp b/clang/test/SemaCXX/lambda-expressions.cpp index 08446a0ee43..17808cef363 100644 --- a/clang/test/SemaCXX/lambda-expressions.cpp +++ b/clang/test/SemaCXX/lambda-expressions.cpp @@ -487,3 +487,15 @@ void foo() { }; } } + +namespace nested_lambda { +template <int N> +class S {}; + +void foo() { + const int num = 18; // expected-note {{'num' declared here}} + auto outer = []() { + auto inner = [](S<num> &X) {}; // expected-error {{variable 'num' cannot be implicitly captured in a lambda with no capture-default specified}} + }; +} +} |

