From f3597653fb1769ac394c18e451c1895545f8583d Mon Sep 17 00:00:00 2001 From: Richard Smith Date: Wed, 10 May 2017 00:01:13 +0000 Subject: [PATCH] When instantiating a friend function template, don't forget to inherit default template arguments from other declarations. llvm-svn: 302603 --- clang/lib/Sema/SemaTemplateInstantiateDecl.cpp | 13 +++++++++++++ clang/test/SemaTemplate/default-arguments.cpp | 16 ++++++++++++++++ 2 files changed, 29 insertions(+) diff --git a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp index 226bd60..03df6fd 100644 --- a/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/clang/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1849,6 +1849,19 @@ Decl *TemplateDeclInstantiator::VisitFunctionDecl(FunctionDecl *D, } } } + + // Check the template parameter list against the previous declaration. The + // goal here is to pick up default arguments added since the friend was + // declared; we know the template parameter lists match, since otherwise + // we would not have picked this template as the previous declaration. + if (TemplateParams && FunctionTemplate->getPreviousDecl()) { + SemaRef.CheckTemplateParameterList( + TemplateParams, + FunctionTemplate->getPreviousDecl()->getTemplateParameters(), + Function->isThisDeclarationADefinition() + ? Sema::TPC_FriendFunctionTemplateDefinition + : Sema::TPC_FriendFunctionTemplate); + } } if (Function->isLocalExternDecl() && !Function->getPreviousDecl()) diff --git a/clang/test/SemaTemplate/default-arguments.cpp b/clang/test/SemaTemplate/default-arguments.cpp index d3e249d..b5b042c 100644 --- a/clang/test/SemaTemplate/default-arguments.cpp +++ b/clang/test/SemaTemplate/default-arguments.cpp @@ -207,3 +207,19 @@ Y y2; } // end ns1 } // end ns PR26134 + +namespace friends { + namespace ns { + template struct A { + template friend void f(); + template friend struct X; + }; + template void f(); // expected-warning 0-1{{extension}} + template struct X; + A a; + } + namespace ns { + void g() { f(); } + X *p; + } +} -- 2.7.4