From: Richard Smith Date: Tue, 16 Jun 2015 21:57:05 +0000 (+0000) Subject: [modules] Fix merging of default template arguments onto friend templates. X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=2aef2bd4b10105ca4661993d42de2db5ac306c8d;p=clang [modules] Fix merging of default template arguments onto friend templates. Previously we'd complain about redefinition of default arguments when we instantiated a class with a friend template that inherits its default argument, because we propagate the default template arguemnt onto the friend when we reload the AST. git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@239857 91177308-0d34-0410-b5e6-96231b3b80d8 --- diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index d0a573981b..f35d1aaf77 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -1922,7 +1922,7 @@ Decl *TemplateDeclInstantiator::VisitTemplateTypeParmDecl( D->isParameterPack()); Inst->setAccess(AS_public); - if (D->hasDefaultArgument()) { + if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { TypeSourceInfo *InstantiatedDefaultArg = SemaRef.SubstType(D->getDefaultArgumentInfo(), TemplateArgs, D->getDefaultArgumentLoc(), D->getDeclName()); @@ -2078,7 +2078,7 @@ Decl *TemplateDeclInstantiator::VisitNonTypeTemplateParmDecl( if (Invalid) Param->setInvalidDecl(); - if (D->hasDefaultArgument()) { + if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { ExprResult Value = SemaRef.SubstExpr(D->getDefaultArgument(), TemplateArgs); if (!Value.isInvalid()) Param->setDefaultArgument(Value.get()); @@ -2205,7 +2205,7 @@ TemplateDeclInstantiator::VisitTemplateTemplateParmDecl( D->getPosition(), D->isParameterPack(), D->getIdentifier(), InstParams); - if (D->hasDefaultArgument()) { + if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) { NestedNameSpecifierLoc QualifierLoc = D->getDefaultArgument().getTemplateQualifierLoc(); QualifierLoc = diff --git a/test/Modules/Inputs/submodules-merge-defs/defs.h b/test/Modules/Inputs/submodules-merge-defs/defs.h index b98cbc3a76..02a4ae946c 100644 --- a/test/Modules/Inputs/submodules-merge-defs/defs.h +++ b/test/Modules/Inputs/submodules-merge-defs/defs.h @@ -61,3 +61,14 @@ namespace StaticInline { static inline void f(X); static inline void g(X x) { f(x); } } + +namespace FriendDefArg { + template struct A; + template struct B; + template class = A> struct C; + template struct Y { + template friend struct A; + template friend struct B; + template class> friend struct C; + }; +} diff --git a/test/Modules/submodules-merge-defs.cpp b/test/Modules/submodules-merge-defs.cpp index cbe2dcdf56..0dd8680b5f 100644 --- a/test/Modules/submodules-merge-defs.cpp +++ b/test/Modules/submodules-merge-defs.cpp @@ -74,3 +74,4 @@ int post_fg = F().g(); J<> post_j; template class K> struct J; J<> post_j2; +FriendDefArg::Y friend_def_arg;