From c54d688c604d28dcb9ab8f92047837c10c8f9c61 Mon Sep 17 00:00:00 2001
From: John McCall <rjmccall@apple.com>
Date: Tue, 19 Oct 2010 05:01:53 +0000
Subject: [PATCH] When instantiating a dependently-scoped friend function
 declaration, we may need to complete the type before looking into it.

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@116795 91177308-0d34-0410-b5e6-96231b3b80d8
---
 lib/Sema/SemaTemplateInstantiateDecl.cpp    |  3 +++
 test/CXX/temp/temp.decls/temp.friend/p1.cpp | 14 ++++++++++++++
 2 files changed, 17 insertions(+)

diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp
index 5636647cda..3d78f1316a 100644
--- a/lib/Sema/SemaTemplateInstantiateDecl.cpp
+++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp
@@ -1333,6 +1333,9 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D,
       SS.setScopeRep(Qualifier);
       SS.setRange(D->getQualifierRange());
       DC = SemaRef.computeDeclContext(SS);
+
+      if (DC && SemaRef.RequireCompleteDeclContext(SS, DC))
+        return 0;
     } else {
       DC = SemaRef.FindInstantiatedContext(D->getLocation(),
                                            D->getDeclContext(),
diff --git a/test/CXX/temp/temp.decls/temp.friend/p1.cpp b/test/CXX/temp/temp.decls/temp.friend/p1.cpp
index 073b2a1463..5e5d7869ff 100644
--- a/test/CXX/temp/temp.decls/temp.friend/p1.cpp
+++ b/test/CXX/temp/temp.decls/temp.friend/p1.cpp
@@ -293,3 +293,17 @@ namespace test13 {
 
   template class Foo<0>;
 }
+
+namespace test14 {
+  template <class T> class B;
+  template <class T> class A {
+    friend void B<T>::foo();
+    static void foo(); // expected-note {{declared private here}}
+  };
+
+  template <class T> class B {
+    void foo() { return A<long>::foo(); } // expected-error {{'foo' is a private member of 'test14::A<long>'}}
+  };
+
+  template class B<int>; // expected-note {{in instantiation}}
+}
-- 
2.40.0