diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index b308613a46..101cae84be 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3362,7 +3362,8 @@ Sema::ActOnFunctionDeclarator(Scope* S, Declarator& D, DeclContext* DC, Diag(NewFD->getLocation(), diag::err_out_of_line_declaration) << D.getCXXScopeSpec().getRange(); NewFD->setInvalidDecl(); - } else if (!Redeclaration) { + } else if (!Redeclaration && + !(isFriend && CurContext->isDependentContext())) { // The user tried to provide an out-of-line definition for a // function that is a member of a class or namespace, but there // was no such member function declared (C++ [class.mfct]p2, diff --git a/test/SemaTemplate/friend-template.cpp b/test/SemaTemplate/friend-template.cpp index 05289b10d2..8bc2631e11 100644 --- a/test/SemaTemplate/friend-template.cpp +++ b/test/SemaTemplate/friend-template.cpp @@ -1,5 +1,4 @@ // RUN: %clang_cc1 -fsyntax-only -verify %s - // PR5057 namespace test0 { namespace std { @@ -107,3 +106,20 @@ namespace test5 { template friend struct cache; }; } + +// PR6022 +namespace PR6022 { + template class A; + + namespace inner { + template + A& f0(A&, T); + } + + template + class A { + template + friend A& inner::f0(A&, T); + }; +} +