forked from OSchip/llvm-project
objective-C arc: Warn under arc about a use of an ivar inside a block
that doesn't have a 'self' as this implicitly captures 'self' and could create retain cycles. Provide fixit. // rdar://11194874 llvm-svn: 165133
This commit is contained in:
parent
8baa61d85d
commit
4a67508685
|
@ -717,6 +717,10 @@ def warn_arc_repeated_use_of_weak : Warning <
|
|||
"but may be unpredictably set to nil; assign to a strong variable to keep "
|
||||
"the object alive">,
|
||||
InGroup<ARCRepeatedUseOfWeak>, DefaultIgnore;
|
||||
def warn_implicitly_retains_self : Warning <
|
||||
"block implicitily retains 'self' - explicitly mention 'self' to indicate "
|
||||
"this is intended behavior">,
|
||||
InGroup<DiagGroup<"implicit-retain-self">>;
|
||||
def warn_arc_possible_repeated_use_of_weak : Warning <
|
||||
"weak %select{variable|property|implicit property|instance variable}0 %1 may "
|
||||
"be accessed multiple times in this %select{function|method|block|lambda}2 "
|
||||
|
|
|
@ -2008,6 +2008,9 @@ Sema::LookupInObjCMethod(LookupResult &Lookup, Scope *S,
|
|||
if (Level != DiagnosticsEngine::Ignored)
|
||||
getCurFunction()->recordUseOfWeak(Result);
|
||||
}
|
||||
if (CurContext->isClosure())
|
||||
Diag(Loc, diag::warn_implicitly_retains_self)
|
||||
<< FixItHint::CreateInsertion(Loc, "self->");
|
||||
}
|
||||
|
||||
return Owned(Result);
|
||||
|
|
|
@ -0,0 +1,20 @@
|
|||
// RUN: cp %s %t
|
||||
// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -fixit %t
|
||||
// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -Werror %t
|
||||
// rdar://11194874
|
||||
|
||||
@interface Root @end
|
||||
|
||||
@interface I : Root
|
||||
{
|
||||
int _bar;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation I
|
||||
- (void)foo{
|
||||
^{
|
||||
_bar = 3;
|
||||
}();
|
||||
}
|
||||
@end
|
|
@ -0,0 +1,18 @@
|
|||
// RUN: %clang_cc1 -x objective-c -fobjc-arc -fblocks -verify %s
|
||||
// rdar://11194874
|
||||
|
||||
@interface Root @end
|
||||
|
||||
@interface I : Root
|
||||
{
|
||||
int _bar;
|
||||
}
|
||||
@end
|
||||
|
||||
@implementation I
|
||||
- (void)foo{
|
||||
^{
|
||||
_bar = 3; // expected-warning {{block implicitily retains 'self' - explicitly mention 'self' to indicate this is intended behavior}}
|
||||
}();
|
||||
}
|
||||
@end
|
|
@ -1,4 +1,4 @@
|
|||
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify -Wno-objc-root-class %s
|
||||
// RUN: %clang_cc1 -fsyntax-only -fobjc-runtime-has-weak -fobjc-arc -fblocks -verify -Wno-objc-root-class -Wno-implicit-retain-self %s
|
||||
|
||||
void *_Block_copy(const void *block);
|
||||
|
||||
|
|
Loading…
Reference in New Issue