Author: rtrieu Date: Fri Mar 4 22:04:57 2016 New Revision: 262765 URL: http://llvm.org/viewvc/llvm-project?rev=262765&view=rev Log: 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. Modified: cfe/trunk/lib/Sema/SemaExpr.cpp cfe/trunk/test/SemaCXX/lambda-expressions.cpp Modified: cfe/trunk/lib/Sema/SemaExpr.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaExpr.cpp?rev=262765&r1=262764&r2=262765&view=diff ============================================================================== --- cfe/trunk/lib/Sema/SemaExpr.cpp (original) +++ cfe/trunk/lib/Sema/SemaExpr.cpp Fri Mar 4 22:04:57 2016 @@ -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 Modified: cfe/trunk/test/SemaCXX/lambda-expressions.cpp URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaCXX/lambda-expressions.cpp?rev=262765&r1=262764&r2=262765&view=diff ============================================================================== --- cfe/trunk/test/SemaCXX/lambda-expressions.cpp (original) +++ cfe/trunk/test/SemaCXX/lambda-expressions.cpp Fri Mar 4 22:04:57 2016 @@ -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}} + }; +} +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits