diff options
author | Ted Kremenek <kremenek@apple.com> | 2011-11-14 21:59:25 +0000 |
---|---|---|
committer | Ted Kremenek <kremenek@apple.com> | 2011-11-14 21:59:25 +0000 |
commit | 2bbcd5ce370753c86d312d2c72a97476ac35b073 (patch) | |
tree | 013bd55a1496cb2af875ba9e7a8d3fe0aefd498e /lib/AST/DeclObjC.cpp | |
parent | 4c42bb7815e4f6317826767f8c53776ae03b4028 (diff) |
ARC: make assignment to 'self' within class methods illegal. Fixes <rdar://problem/10416568>.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@144572 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/AST/DeclObjC.cpp')
-rw-r--r-- | lib/AST/DeclObjC.cpp | 31 |
1 files changed, 20 insertions, 11 deletions
diff --git a/lib/AST/DeclObjC.cpp b/lib/AST/DeclObjC.cpp index 35ee7c6ccd..766b673bde 100644 --- a/lib/AST/DeclObjC.cpp +++ b/lib/AST/DeclObjC.cpp @@ -580,17 +580,26 @@ void ObjCMethodDecl::createImplicitParams(ASTContext &Context, bool selfIsPseudoStrong = false; bool selfIsConsumed = false; - if (isInstanceMethod() && Context.getLangOptions().ObjCAutoRefCount) { - selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); - - // 'self' is always __strong. It's actually pseudo-strong except - // 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 && !selfIsConsumed) { + + if (Context.getLangOptions().ObjCAutoRefCount) { + if (isInstanceMethod()) { + selfIsConsumed = hasAttr<NSConsumesSelfAttr>(); + + // 'self' is always __strong. It's actually pseudo-strong except + // 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 && !selfIsConsumed) { + selfTy = selfTy.withConst(); + selfIsPseudoStrong = true; + } + } + else { + assert(isClassMethod()); + // 'self' is always const in class methods. selfTy = selfTy.withConst(); selfIsPseudoStrong = true; } |