diff options
author | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-07-07 05:58:48 +0000 |
---|---|---|
committer | Richard Smith <richard-llvm@metafoo.co.uk> | 2018-07-07 05:58:48 +0000 |
commit | d82201e7c66b8d49b6a1ae128bbd6b9175cb90d3 (patch) | |
tree | fab326e166fbc1b48131ebf46c1ffd0b7cd9a94f /clang/lib/Sema | |
parent | 9659a127a34402d02637e0f52bfab9ee7543fb5b (diff) | |
download | bcm5719-llvm-d82201e7c66b8d49b6a1ae128bbd6b9175cb90d3.tar.gz bcm5719-llvm-d82201e7c66b8d49b6a1ae128bbd6b9175cb90d3.zip |
P0806R2 Implicit capture of this with a capture-default of [=] is
deprecated.
Add a -Wdeprecated warning for this in C++2a onwards. (In C++17 and
before, there isn't a reasonable alternative because [=,this] is
ill-formed.)
llvm-svn: 336480
Diffstat (limited to 'clang/lib/Sema')
-rw-r--r-- | clang/lib/Sema/SemaLambda.cpp | 11 |
1 files changed, 11 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaLambda.cpp b/clang/lib/Sema/SemaLambda.cpp index fcacc2a17c9..5e69feceda6 100644 --- a/clang/lib/Sema/SemaLambda.cpp +++ b/clang/lib/Sema/SemaLambda.cpp @@ -1548,6 +1548,17 @@ ExprResult Sema::BuildLambdaExpr(SourceLocation StartLoc, SourceLocation EndLoc, // Handle 'this' capture. if (From.isThisCapture()) { + // Capturing 'this' implicitly with a default of '[=]' is deprecated, + // because it results in a reference capture. Don't warn prior to + // C++2a; there's nothing that can be done about it before then. + if (getLangOpts().CPlusPlus2a && IsImplicit && + CaptureDefault == LCD_ByCopy) { + Diag(From.getLocation(), diag::warn_deprecated_this_capture); + Diag(CaptureDefaultLoc, diag::note_deprecated_this_capture) + << FixItHint::CreateInsertion( + getLocForEndOfToken(CaptureDefaultLoc), ", this"); + } + Captures.push_back( LambdaCapture(From.getLocation(), IsImplicit, From.isCopyCapture() ? LCK_StarThis : LCK_This)); |