diff options
author | Douglas Gregor <dgregor@apple.com> | 2009-11-13 23:14:53 +0000 |
---|---|---|
committer | Douglas Gregor <dgregor@apple.com> | 2009-11-13 23:14:53 +0000 |
commit | cad84b7c12564ff37feb66d6d004bb609bea8788 (patch) | |
tree | afab19a2565e6069b475747c8b4946490d59d94a /lib/Sema/SemaTemplateInstantiateDecl.cpp | |
parent | 65d0e28583ac050ec9aa71b469285faad48d137e (diff) |
A constructor template cannot be instantiated to a copy
constructor. Make sure that such declarations can never be formed.
git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@88718 91177308-0d34-0410-b5e6-96231b3b80d8
Diffstat (limited to 'lib/Sema/SemaTemplateInstantiateDecl.cpp')
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 47 |
1 files changed, 30 insertions, 17 deletions
diff --git a/lib/Sema/SemaTemplateInstantiateDecl.cpp b/lib/Sema/SemaTemplateInstantiateDecl.cpp index 47d2701bcd..0e42bd65db 100644 --- a/lib/Sema/SemaTemplateInstantiateDecl.cpp +++ b/lib/Sema/SemaTemplateInstantiateDecl.cpp @@ -658,6 +658,12 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { TemplateParams, Function); Function->setDescribedFunctionTemplate(FunctionTemplate); FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); + } else if (FunctionTemplate) { + // Record this function template specialization. + Function->setFunctionTemplateSpecialization(SemaRef.Context, + FunctionTemplate, + &TemplateArgs.getInnermost(), + InsertPos); } if (InitFunctionInstantiation(Function, D)) @@ -709,14 +715,6 @@ Decl *TemplateDeclInstantiator::VisitCXXRecordDecl(CXXRecordDecl *D) { Function->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); } - if (FunctionTemplate && !TemplateParams) { - // Record this function template specialization. - Function->setFunctionTemplateSpecialization(SemaRef.Context, - FunctionTemplate, - &TemplateArgs.getInnermost(), - InsertPos); - } - return Function; } @@ -811,9 +809,17 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, if (D->isOutOfLine()) FunctionTemplate->setLexicalDeclContext(D->getLexicalDeclContext()); Method->setDescribedFunctionTemplate(FunctionTemplate); - } else if (!FunctionTemplate) + } else if (FunctionTemplate) { + // Record this function template specialization. + Method->setFunctionTemplateSpecialization(SemaRef.Context, + FunctionTemplate, + &TemplateArgs.getInnermost(), + InsertPos); + } else { + // Record this instantiation of a member function. Method->setInstantiationOfMemberFunction(D, TSK_ImplicitInstantiation); - + } + // If we are instantiating a member function defined // out-of-line, the instantiation will have the same lexical // context (which will be a namespace scope) as the template. @@ -825,6 +831,20 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, Params[P]->setOwningFunction(Method); Method->setParams(SemaRef.Context, Params.data(), Params.size()); + if (CXXConstructorDecl *Constructor = dyn_cast<CXXConstructorDecl>(Method)) { + // C++ [class.copy]p3: + // [...] A member function template is never instantiated to perform the + // copy of a class object to an object of its class type. + if (FunctionTemplate && !TemplateParams && + Constructor->isCopyConstructor(SemaRef.Context)) { + SemaRef.Diag(Constructor->getLocation(), + diag::err_constructor_template_is_copy_constructor) + << Constructor; + Method->setInvalidDecl(); + return Method; + } + } + if (InitMethodInstantiation(Method, D)) Method->setInvalidDecl(); @@ -843,13 +863,6 @@ TemplateDeclInstantiator::VisitCXXMethodDecl(CXXMethodDecl *D, PrevDecl = 0; } - if (FunctionTemplate && !TemplateParams) - // Record this function template specialization. - Method->setFunctionTemplateSpecialization(SemaRef.Context, - FunctionTemplate, - &TemplateArgs.getInnermost(), - InsertPos); - bool Redeclaration = false; bool OverloadableAttrRequired = false; SemaRef.CheckFunctionDeclaration(Method, PrevDecl, false, Redeclaration, |