Fix <rdar://problem/6320086> parser rejects block capturing ivar.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@59444 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/Sema.cpp b/lib/Sema/Sema.cpp
index b78336b..6495949 100644
--- a/lib/Sema/Sema.cpp
+++ b/lib/Sema/Sema.cpp
@@ -241,5 +241,8 @@
}
ObjCMethodDecl *Sema::getCurMethodDecl() {
- return dyn_cast<ObjCMethodDecl>(CurContext);
+ DeclContext *DC = CurContext;
+ while (isa<BlockDecl>(DC))
+ DC = DC->getParent();
+ return dyn_cast<ObjCMethodDecl>(DC);
}
diff --git a/test/SemaObjC/block-ivar.m b/test/SemaObjC/block-ivar.m
new file mode 100644
index 0000000..d1f56b6
--- /dev/null
+++ b/test/SemaObjC/block-ivar.m
@@ -0,0 +1,19 @@
+// RUN: clang -fsyntax-only -verify %s
+
+@interface NSObject {
+ struct objc_object *isa;
+}
+@end
+@interface Foo : NSObject {
+ int _prop;
+}
+@end
+
+@implementation Foo
+- (int)doSomething {
+ int (^blk)(void) = ^{ return _prop; };
+ return blk();
+}
+
+@end
+