diff --git a/clang/lib/Sema/SemaExprObjC.cpp b/clang/lib/Sema/SemaExprObjC.cpp index 22a1b19921b9..cf38225de0cf 100644 --- a/clang/lib/Sema/SemaExprObjC.cpp +++ b/clang/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/clang/test/SemaObjC/self-in-function.m b/clang/test/SemaObjC/self-in-function.m index 901cc31e47ae..9027a947a03c 100644 --- a/clang/test/SemaObjC/self-in-function.m +++ b/clang/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) {