When inside an Objective-C++ method, name lookup should look into the
interface for ivars before assuming that this is an unresolved
function name.

Fixes <rdar://problem/6590445>.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@64653 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/Sema/SemaExpr.cpp b/lib/Sema/SemaExpr.cpp
index 07079db..553c29e 100644
--- a/lib/Sema/SemaExpr.cpp
+++ b/lib/Sema/SemaExpr.cpp
@@ -565,20 +565,6 @@
   LookupResult Lookup = LookupParsedName(S, SS, Name, LookupOrdinaryName,
                                          false, true, Loc);
 
-  if (getLangOptions().CPlusPlus && (!SS || !SS->isSet()) && 
-      HasTrailingLParen && Lookup.getKind() == LookupResult::NotFound) {
-    // We've seen something of the form
-    //
-    //   identifier(
-    //
-    // and we did not find any entity by the name
-    // "identifier". However, this identifier is still subject to
-    // argument-dependent lookup, so keep track of the name.
-    return Owned(new (Context) UnresolvedFunctionNameExpr(Name,
-                                                          Context.OverloadTy,
-                                                          Loc));
-  }
-
   NamedDecl *D = 0;
   if (Lookup.isAmbiguous()) {
     DiagnoseAmbiguousLookup(Lookup, Name, Loc,
@@ -621,6 +607,21 @@
       return Owned(new (Context) ObjCSuperExpr(Loc, T));
     }
   }
+
+  if (getLangOptions().CPlusPlus && (!SS || !SS->isSet()) && 
+      HasTrailingLParen && D == 0) {
+    // We've seen something of the form
+    //
+    //   identifier(
+    //
+    // and we did not find any entity by the name
+    // "identifier". However, this identifier is still subject to
+    // argument-dependent lookup, so keep track of the name.
+    return Owned(new (Context) UnresolvedFunctionNameExpr(Name,
+                                                          Context.OverloadTy,
+                                                          Loc));
+  }
+
   if (D == 0) {
     // Otherwise, this could be an implicitly declared function reference (legal
     // in C90, extension in C99).
diff --git a/test/SemaObjCXX/blocks.mm b/test/SemaObjCXX/blocks.mm
index a792006..34f75a0 100644
--- a/test/SemaObjCXX/blocks.mm
+++ b/test/SemaObjCXX/blocks.mm
@@ -24,3 +24,23 @@
 void foo5(id (^x)(int)) {
   if (x) { }
 }
+
+// <rdar://problem/6590445>
+@interface Foo {
+    @private
+    void (^_block)(void);
+}
+- (void)bar;
+@end
+
+namespace N {
+  class X { };      
+  void foo(X);
+}
+
+@implementation Foo
+- (void)bar {
+    _block();
+    foo(N::X()); // okay
+}
+@end