]> granicus.if.org Git - clang/commitdiff
Relax restriction of assigning to 'self' in ARC when a method is attributed with...
authorTed Kremenek <kremenek@apple.com>
Tue, 25 Oct 2011 04:52:20 +0000 (04:52 +0000)
committerTed Kremenek <kremenek@apple.com>
Tue, 25 Oct 2011 04:52:20 +0000 (04:52 +0000)
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@142909 91177308-0d34-0410-b5e6-96231b3b80d8

lib/AST/DeclObjC.cpp
test/SemaObjC/arc.m

index 7eb2688134bef92f52715330478736657fd5780b..5c4d25fd0260424c110f3473e6b7e01ade18f090 100644 (file)
@@ -577,13 +577,13 @@ void ObjCMethodDecl::createImplicitParams(ASTContext &Context,
     selfIsConsumed = hasAttr<NSConsumesSelfAttr>();
 
     // 'self' is always __strong.  It's actually pseudo-strong except
-    // in init methods, though.
+    // in init methods (or methods labeled ns_consumes_self), though.
     Qualifiers qs;
     qs.setObjCLifetime(Qualifiers::OCL_Strong);
     selfTy = Context.getQualifiedType(selfTy, qs);
 
     // In addition, 'self' is const unless this is an init method.
-    if (getMethodFamily() != OMF_init) {
+    if (getMethodFamily() != OMF_init && !selfIsConsumed) {
       selfTy = selfTy.withConst();
       selfIsPseudoStrong = true;
     }
index 3f4c406458f8937e3d644a78b021e6539d21bf44..d146d8fad1d5f757fedd6c1a5c12d6980f0f4dfc 100644 (file)
@@ -294,6 +294,16 @@ void test12(id collection) {
 }
 @end
 
+// <rdar://problem/10274056>
+@interface Test13_B
+- (id) consumesSelf __attribute__((ns_consumes_self));
+@end
+@implementation Test13_B
+- (id) consumesSelf {
+  self = 0; // no-warning
+}
+@end
+
 // rdar://problem/9172151
 @class Test14A, Test14B;
 void test14() {