diff options
Diffstat (limited to 'clang/lib/Sema/SemaExpr.cpp')
-rw-r--r-- | clang/lib/Sema/SemaExpr.cpp | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/clang/lib/Sema/SemaExpr.cpp b/clang/lib/Sema/SemaExpr.cpp index eddc4207dfc..7caa50e07cf 100644 --- a/clang/lib/Sema/SemaExpr.cpp +++ b/clang/lib/Sema/SemaExpr.cpp @@ -13502,6 +13502,23 @@ static bool captureInBlock(BlockScopeInfo *BSI, VarDecl *Var, } return false; } + + // Warn about implicitly autoreleasing indirect parameters captured by blocks. + if (auto *PT = dyn_cast<PointerType>(CaptureType)) { + QualType PointeeTy = PT->getPointeeType(); + if (isa<ObjCObjectPointerType>(PointeeTy.getCanonicalType()) && + PointeeTy.getObjCLifetime() == Qualifiers::OCL_Autoreleasing && + !isa<AttributedType>(PointeeTy)) { + if (BuildAndDiagnose) { + SourceLocation VarLoc = Var->getLocation(); + S.Diag(Loc, diag::warn_block_capture_autoreleasing); + S.Diag(VarLoc, diag::note_declare_parameter_autoreleasing) << + FixItHint::CreateInsertion(VarLoc, "__autoreleasing"); + S.Diag(VarLoc, diag::note_declare_parameter_strong); + } + } + } + const bool HasBlocksAttr = Var->hasAttr<BlocksAttr>(); if (HasBlocksAttr || CaptureType->isReferenceType() || (S.getLangOpts().OpenMP && S.IsOpenMPCapturedDecl(Var))) { |