@@ -5749,20 +5749,24 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
57495749 std::unique_ptr<TemplateInstantiationError> error =
57505750 ctx.getClangTemplateArguments (func->getTemplateParameters (),
57515751 subst.getReplacementTypes (), templateSubst);
5752- if (error) {
5753- std::string failedTypesStr;
5754- llvm::raw_string_ostream failedTypesStrStream (failedTypesStr);
5755- llvm::interleaveComma (error->failedTypes , failedTypesStrStream);
57565752
5753+ auto getFuncName = [&]() -> std::string {
57575754 std::string funcName;
57585755 llvm::raw_string_ostream funcNameStream (funcName);
57595756 func->printQualifiedName (funcNameStream);
5757+ return funcName;
5758+ };
5759+
5760+ if (error) {
5761+ std::string failedTypesStr;
5762+ llvm::raw_string_ostream failedTypesStrStream (failedTypesStr);
5763+ llvm::interleaveComma (error->failedTypes , failedTypesStrStream);
57605764
57615765 // TODO: Use the location of the apply here.
57625766 // TODO: This error message should not reference implementation details.
57635767 // See: https://github.com/apple/swift/pull/33053#discussion_r477003350
57645768 ctx.Diags .diagnose (SourceLoc (), diag::unable_to_convert_generic_swift_types,
5765- funcName , failedTypesStr);
5769+ getFuncName () , failedTypesStr);
57665770 return nullptr ;
57675771 }
57685772
@@ -5772,6 +5776,20 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
57725776 auto &sema = getClangInstance ().getSema ();
57735777 auto *spec = sema.InstantiateFunctionDeclaration (func, templateArgList,
57745778 clang::SourceLocation ());
5779+ if (!spec) {
5780+ std::string templateParams;
5781+ llvm::raw_string_ostream templateParamsStream (templateParams);
5782+ llvm::interleaveComma (templateArgList->asArray (), templateParamsStream,
5783+ [&](const clang::TemplateArgument &arg) {
5784+ arg.print (func->getASTContext ().getPrintingPolicy (),
5785+ templateParamsStream,
5786+ /* IncludeType*/ true );
5787+ });
5788+ ctx.Diags .diagnose (SourceLoc (),
5789+ diag::unable_to_substitute_cxx_function_template,
5790+ getFuncName (), templateParams);
5791+ return nullptr ;
5792+ }
57755793 sema.InstantiateFunctionDefinition (clang::SourceLocation (), spec);
57765794 return spec;
57775795}
0 commit comments