]> granicus.if.org Git - clang/commitdiff
Also 'self' in blocks need be handled specially.
authorFariborz Jahanian <fjahanian@apple.com>
Mon, 28 Mar 2011 16:23:34 +0000 (16:23 +0000)
committerFariborz Jahanian <fjahanian@apple.com>
Mon, 28 Mar 2011 16:23:34 +0000 (16:23 +0000)
// rdar://9181463

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128410 91177308-0d34-0410-b5e6-96231b3b80d8

lib/Sema/SemaExprObjC.cpp
test/SemaObjC/self-in-function.m

index 22a1b19921b9146d253928bd4a0813863ec954ca..cf38225de0cf9bd3c5f08972d0a32f8c590d2502 100644 (file)
@@ -325,7 +325,10 @@ bool Sema::CheckMessageArgumentTypes(Expr **Args, unsigned NumArgs,
 
 bool Sema::isSelfExpr(Expr *RExpr) {
   // 'self' is objc 'self' in an objc method only.
-  if (!isa<ObjCMethodDecl>(CurContext))
+  DeclContext *DC = CurContext;
+  while (isa<BlockDecl>(DC))
+    DC = DC->getParent();
+  if (DC && !isa<ObjCMethodDecl>(DC))
     return false;
   if (ImplicitCastExpr *ICE = dyn_cast<ImplicitCastExpr>(RExpr))
     if (ICE->getCastKind() == CK_LValueToRValue)
index 901cc31e47ae09c8b4a9561dd50f016aeb9884ab..9027a947a03c981124c6e2f6ae09f517ed43c89a 100644 (file)
@@ -1,4 +1,4 @@
-// RUN: %clang_cc1  -fsyntax-only -verify %s
+// RUN: %clang_cc1  -fsyntax-only -fblocks -verify %s
 // rdar://9181463
 
 typedef struct objc_class *Class;
@@ -14,6 +14,9 @@ typedef struct objc_object {
 
 void foo(Class self) {
   [self alloc];
+  (^() {
+    [self alloc];
+   })();
 }
 
 void bar(Class self) {