When performing unqualified name lookup into a DeclContext, also look into
all of the parent DeclContexts that aren't represented within the
Scope chain. This fixes some name-lookup problems in out-of-line
definitions of members of nested classes.


git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@81451 91177308-0d34-0410-b5e6-96231b3b80d8
diff --git a/lib/AST/DeclBase.cpp b/lib/AST/DeclBase.cpp
index 34bc2b9..8d16139 100644
--- a/lib/AST/DeclBase.cpp
+++ b/lib/AST/DeclBase.cpp
@@ -420,6 +420,22 @@
     (*D++)->Destroy(C);
 }
 
+/// \brief Find the parent context of this context that will be
+/// used for unqualified name lookup.
+///
+/// Generally, the parent lookup context is the semantic context. However, for
+/// a friend function the parent lookup context is the lexical context, which
+/// is the class in which the friend is declared.
+DeclContext *DeclContext::getLookupParent() {
+  // FIXME: Find a better way to identify friends
+  if (isa<FunctionDecl>(this))
+    if (getParent()->getLookupContext()->isFileContext() &&
+        getLexicalParent()->getLookupContext()->isRecord())
+      return getLexicalParent();
+  
+  return getParent();
+}
+
 bool DeclContext::isDependentContext() const {
   if (isFileContext())
     return false;