diff options
Diffstat (limited to 'lib')
-rw-r--r-- | lib/AST/DeclCXX.cpp | 16 | ||||
-rw-r--r-- | lib/Sema/SemaDecl.cpp | 3 | ||||
-rw-r--r-- | lib/Sema/SemaOverload.cpp | 4 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateDeduction.cpp | 2 | ||||
-rw-r--r-- | lib/Sema/SemaTemplateInstantiateDecl.cpp | 47 |
5 files changed, 45 insertions, 27 deletions
diff --git a/lib/AST/DeclCXX.cpp b/lib/AST/DeclCXX.cpp index e325a25c76..69a577f1e7 100644 --- a/lib/AST/DeclCXX.cpp +++ b/lib/AST/DeclCXX.cpp @@ -707,23 +707,23 @@ CXXConstructorDecl::isCopyConstructor(ASTContext &Context, // if its first parameter is of type X&, const X&, volatile X& or // const volatile X&, and either there are no other parameters // or else all other parameters have default arguments (8.3.6). + // + // Note that we also test cv 'X' as a copy constructor, even though it is + // ill-formed, because this helps enforce C++ [class.copy]p3. if ((getNumParams() < 1) || (getNumParams() > 1 && !getParamDecl(1)->hasDefaultArg()) || - (getPrimaryTemplate() != 0) || (getDescribedFunctionTemplate() != 0)) return false; const ParmVarDecl *Param = getParamDecl(0); // Do we have a reference type? Rvalue references don't count. - const LValueReferenceType *ParamRefType = - Param->getType()->getAs<LValueReferenceType>(); - if (!ParamRefType) - return false; + CanQualType PointeeType = Context.getCanonicalType(Param->getType()); + if (CanQual<LValueReferenceType> ParamRefType = + PointeeType->getAs<LValueReferenceType>()) + PointeeType = ParamRefType->getPointeeType(); - // Is it a reference to our class type? - CanQualType PointeeType - = Context.getCanonicalType(ParamRefType->getPointeeType()); + // Do we have our class type? CanQualType ClassTy = Context.getCanonicalType(Context.getTagDeclType(getParent())); if (PointeeType.getUnqualifiedType() != ClassTy) diff --git a/lib/Sema/SemaDecl.cpp b/lib/Sema/SemaDecl.cpp index fa31cc5ddb..30d046f3b9 100644 --- a/lib/Sema/SemaDecl.cpp +++ b/lib/Sema/SemaDecl.cpp @@ -3909,6 +3909,9 @@ Sema::DeclPtrTy Sema::ActOnStartOfFunctionDef(Scope *FnBodyScope, DeclPtrTy D) { << FD->getNameAsCString() << "dllimport"; } } + + assert(ExprTemporaries.empty() && "Leftover temporaries before starting"); + return DeclPtrTy::make(FD); } diff --git a/lib/Sema/SemaOverload.cpp b/lib/Sema/SemaOverload.cpp index 3948b22f7b..70b080e678 100644 --- a/lib/Sema/SemaOverload.cpp +++ b/lib/Sema/SemaOverload.cpp @@ -2237,7 +2237,9 @@ Sema::AddOverloadCandidate(FunctionDecl *Function, // argument doesn't participate in overload resolution. } - if (!CandidateSet.isNewCandidate(Function)) + // FIXME: It would be nice if it were safe to keep invalid methods in the + // overload set (but it isn't due to broken copy constructors). + if (!CandidateSet.isNewCandidate(Function) || Function->isInvalidDecl()) return; // Add this candidate diff --git a/lib/Sema/SemaTemplateDeduction.cpp b/lib/Sema/SemaTemplateDeduction.cpp index fa45806a72..17b4e5fe82 100644 --- a/lib/Sema/SemaTemplateDeduction.cpp +++ b/lib/Sema/SemaTemplateDeduction.cpp @@ -1247,7 +1247,7 @@ Sema::FinishTemplateArgumentDeduction(FunctionTemplateDecl *FunctionTemplate, for (unsigned I = 0, N = Deduced.size(); I != N; ++I) { if (Deduced[I].isNull()) { Info.Param = makeTemplateParameter( - const_cast<NamedDecl *>(TemplateParams->getParam(I))); + const_cast<NamedDecl *>(TemplateParams->getParam(I))); return TDK_Incomplete; } 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, |