diff --git a/clang/include/clang/Sema/Sema.h b/clang/include/clang/Sema/Sema.h --- a/clang/include/clang/Sema/Sema.h +++ b/clang/include/clang/Sema/Sema.h @@ -9138,7 +9138,7 @@ /// a dependent parameter type did not match the corresponding element /// of the corresponding argument (when deducing from an initializer list). TDK_DeducedMismatchNested, - /// A non-depnedent component of the parameter did not match the + /// A non-dependent component of the parameter did not match the /// corresponding component of the argument. TDK_NonDeducedMismatch, /// When performing template argument deduction for a function @@ -9232,6 +9232,12 @@ sema::TemplateDeductionInfo &Info, bool IsAddressOfFunction = false); + static Sema::TemplateDeductionResult DeduceTemplateArgumentsByTypeMatch( + Sema &S, TemplateParameterList *TemplateParams, QualType P, QualType A, + sema::TemplateDeductionInfo &Info, + SmallVectorImpl &Deduced, unsigned TDF, + bool PartialOrdering = false, bool DeducedFromArrayBound = false); + /// Substitute Replacement for \p auto in \p TypeWithAuto QualType SubstAutoType(QualType TypeWithAuto, QualType Replacement); /// Substitute Replacement for auto in TypeWithAuto diff --git a/clang/lib/Sema/SemaCodeComplete.cpp b/clang/lib/Sema/SemaCodeComplete.cpp --- a/clang/lib/Sema/SemaCodeComplete.cpp +++ b/clang/lib/Sema/SemaCodeComplete.cpp @@ -41,6 +41,7 @@ #include "clang/Sema/ScopeInfo.h" #include "clang/Sema/Sema.h" #include "clang/Sema/SemaInternal.h" +// #include "clang/Sema/Template.h" #include "llvm/ADT/ArrayRef.h" #include "llvm/ADT/DenseSet.h" #include "llvm/ADT/SmallBitVector.h" @@ -1463,6 +1464,38 @@ OverloadSet.Add(Method, Results.size()); } +#if 0 + const FunctionTemplateDecl *FTD = nullptr; + FTD = dyn_cast(R.Declaration); + llvm::errs() << "SCC 0: " << (void *)FTD << " " << PreferredType.isNull() + << "\n"; + if (FTD && PreferredType) { + auto Pointee = PreferredType->getTypePtr()->getPointeeType(); + llvm::errs() << "SCC 1\n"; + if (!Pointee.isNull()) { + llvm::errs() << "SCC 2\n"; + if (const auto *FT = Pointee->getAs()) { + llvm::errs() << "SCC 3\n"; + sema::TemplateDeductionInfo Info(SourceLocation{}); + llvm::SmallVector Deduced; + Deduced.resize(FTD->getTemplateParameters()->size()); + FT->dump(); + if (auto Result = Sema::DeduceTemplateArgumentsByTypeMatch( + SemaRef, FTD->getTemplateParameters(), + FTD->getTemplatedDecl()->getType(), + FT->getCanonicalTypeInternal(), Info, Deduced, 48)) { + llvm::errs() << FTD->getNameAsString() + << " could not be deduced from enclosing type: " + << Result << "\n"; + } else + llvm::errs() << FTD->getNameAsString() + << " could be deduced from enclosing type" + << "\n"; + } + } + } +#endif + R.FunctionCanBeCall = canFunctionBeCalled(R.getDeclaration(), BaseExprType); // Insert this result into the set of results. diff --git a/clang/lib/Sema/SemaOverload.cpp b/clang/lib/Sema/SemaOverload.cpp --- a/clang/lib/Sema/SemaOverload.cpp +++ b/clang/lib/Sema/SemaOverload.cpp @@ -12460,6 +12460,7 @@ // overloaded functions considered. FunctionDecl *Specialization = nullptr; TemplateDeductionInfo Info(FailedCandidates.getLocation()); + // TargetFunctionType->dump(llvm::errs(), Context); if (Sema::TemplateDeductionResult Result = S.DeduceTemplateArguments(FunctionTemplate, &OvlExplicitTemplateArgs, diff --git a/clang/lib/Sema/SemaTemplateDeduction.cpp b/clang/lib/Sema/SemaTemplateDeduction.cpp --- a/clang/lib/Sema/SemaTemplateDeduction.cpp +++ b/clang/lib/Sema/SemaTemplateDeduction.cpp @@ -2239,6 +2239,16 @@ llvm_unreachable("Invalid Type Class!"); } +Sema::TemplateDeductionResult Sema::DeduceTemplateArgumentsByTypeMatch( + Sema &S, TemplateParameterList *TemplateParams, QualType P, QualType A, + sema::TemplateDeductionInfo &Info, + SmallVectorImpl &Deduced, unsigned TDF, + bool PartialOrdering, bool DeducedFromArrayBound) { + return ::DeduceTemplateArgumentsByTypeMatch(S, TemplateParams, P, A, Info, + Deduced, TDF, PartialOrdering, + DeducedFromArrayBound); +} + static Sema::TemplateDeductionResult DeduceTemplateArguments(Sema &S, TemplateParameterList *TemplateParams, const TemplateArgument &P, TemplateArgument A,