r302603 - When instantiating a friend function template, don't forget to inherit default template arguments from other declarations.
Richard Smith via cfe-commits
cfe-commits at lists.llvm.org
Tue May 9 17:01:13 PDT 2017
Author: rsmith
Date: Tue May 9 19:01:13 2017
New Revision: 302603
URL: http://llvm.org/viewvc/llvm-project?rev=302603&view=rev
Log:
When instantiating a friend function template, don't forget to inherit default template arguments from other declarations.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/SemaTemplate/default-arguments.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=302603&r1=302602&r2=302603&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue May 9 19:01:13 2017
@@ -1849,6 +1849,19 @@ Decl *TemplateDeclInstantiator::VisitFun
}
}
}
+
+ // 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())
Modified: cfe/trunk/test/SemaTemplate/default-arguments.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/SemaTemplate/default-arguments.cpp?rev=302603&r1=302602&r2=302603&view=diff
==============================================================================
--- cfe/trunk/test/SemaTemplate/default-arguments.cpp (original)
+++ cfe/trunk/test/SemaTemplate/default-arguments.cpp Tue May 9 19:01:13 2017
@@ -207,3 +207,19 @@ Y<false> y2;
} // end ns1
} // end ns PR26134
+
+namespace friends {
+ namespace ns {
+ template<typename> struct A {
+ template<typename> friend void f();
+ template<typename> friend struct X;
+ };
+ template<typename = int> void f(); // expected-warning 0-1{{extension}}
+ template<typename = int> struct X;
+ A<int> a;
+ }
+ namespace ns {
+ void g() { f(); }
+ X<int> *p;
+ }
+}
More information about the cfe-commits
mailing list