that doesn't have a 'self' as this implicitly captures 'self' and could
create retain cycles. Provide fixit. // rdar://
11194874
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@165133
91177308-0d34-0410-b5e6-
96231b3b80d8
"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 "
if (Level != DiagnosticsEngine::Ignored)
getCurFunction()->recordUseOfWeak(Result);
}
+ if (CurContext->isClosure())
+ Diag(Loc, diag::warn_implicitly_retains_self)
+ << FixItHint::CreateInsertion(Loc, "self->");
}
return Owned(Result);
--- /dev/null
+// 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
--- /dev/null
+// 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
-// 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);