From b460210fe0dec08971edfe33c294323cf79cb894 Mon Sep 17 00:00:00 2001 From: Fariborz Jahanian Date: Mon, 28 Mar 2011 16:23:34 +0000 Subject: [PATCH] Also 'self' in blocks need be handled specially. // rdar://9181463 git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@128410 91177308-0d34-0410-b5e6-96231b3b80d8 --- lib/Sema/SemaExprObjC.cpp | 5 ++++- test/SemaObjC/self-in-function.m | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/lib/Sema/SemaExprObjC.cpp b/lib/Sema/SemaExprObjC.cpp index 22a1b19921..cf38225de0 100644 --- a/lib/Sema/SemaExprObjC.cpp +++ b/lib/Sema/SemaExprObjC.cpp @@ -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(CurContext)) + DeclContext *DC = CurContext; + while (isa(DC)) + DC = DC->getParent(); + if (DC && !isa(DC)) return false; if (ImplicitCastExpr *ICE = dyn_cast(RExpr)) if (ICE->getCastKind() == CK_LValueToRValue) diff --git a/test/SemaObjC/self-in-function.m b/test/SemaObjC/self-in-function.m index 901cc31e47..9027a947a0 100644 --- a/test/SemaObjC/self-in-function.m +++ b/test/SemaObjC/self-in-function.m @@ -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) { -- 2.40.0