r239857 - [modules] Fix merging of default template arguments onto friend templates.
Richard Smith
richard-llvm at metafoo.co.uk
Tue Jun 16 14:57:06 PDT 2015
Author: rsmith
Date: Tue Jun 16 16:57:05 2015
New Revision: 239857
URL: http://llvm.org/viewvc/llvm-project?rev=239857&view=rev
Log:
[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.
Modified:
cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h
cfe/trunk/test/Modules/submodules-merge-defs.cpp
Modified: cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp?rev=239857&r1=239856&r2=239857&view=diff
==============================================================================
--- cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp (original)
+++ cfe/trunk/lib/Sema/SemaTemplateInstantiateDecl.cpp Tue Jun 16 16:57:05 2015
@@ -1922,7 +1922,7 @@ Decl *TemplateDeclInstantiator::VisitTem
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::VisitNon
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::VisitTemplateT
D->getPosition(),
D->isParameterPack(),
D->getIdentifier(), InstParams);
- if (D->hasDefaultArgument()) {
+ if (D->hasDefaultArgument() && !D->defaultArgumentWasInherited()) {
NestedNameSpecifierLoc QualifierLoc =
D->getDefaultArgument().getTemplateQualifierLoc();
QualifierLoc =
Modified: cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h?rev=239857&r1=239856&r2=239857&view=diff
==============================================================================
--- cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h (original)
+++ cfe/trunk/test/Modules/Inputs/submodules-merge-defs/defs.h Tue Jun 16 16:57:05 2015
@@ -61,3 +61,14 @@ namespace StaticInline {
static inline void f(X);
static inline void g(X x) { f(x); }
}
+
+namespace FriendDefArg {
+ template<typename = int> struct A;
+ template<int = 0> struct B;
+ template<template<typename> class = A> struct C;
+ template<typename U> struct Y {
+ template<typename> friend struct A;
+ template<int> friend struct B;
+ template<template<typename> class> friend struct C;
+ };
+}
Modified: cfe/trunk/test/Modules/submodules-merge-defs.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/test/Modules/submodules-merge-defs.cpp?rev=239857&r1=239856&r2=239857&view=diff
==============================================================================
--- cfe/trunk/test/Modules/submodules-merge-defs.cpp (original)
+++ cfe/trunk/test/Modules/submodules-merge-defs.cpp Tue Jun 16 16:57:05 2015
@@ -74,3 +74,4 @@ int post_fg = F<char>().g<int>();
J<> post_j;
template<typename T, int N, template<typename> class K> struct J;
J<> post_j2;
+FriendDefArg::Y<int> friend_def_arg;
More information about the cfe-commits
mailing list