@@ -5749,20 +5749,24 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
5749
5749
std::unique_ptr<TemplateInstantiationError> error =
5750
5750
ctx.getClangTemplateArguments (func->getTemplateParameters (),
5751
5751
subst.getReplacementTypes (), templateSubst);
5752
- if (error) {
5753
- std::string failedTypesStr;
5754
- llvm::raw_string_ostream failedTypesStrStream (failedTypesStr);
5755
- llvm::interleaveComma (error->failedTypes , failedTypesStrStream);
5756
5752
5753
+ auto getFuncName = [&]() -> std::string {
5757
5754
std::string funcName;
5758
5755
llvm::raw_string_ostream funcNameStream (funcName);
5759
5756
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);
5760
5764
5761
5765
// TODO: Use the location of the apply here.
5762
5766
// TODO: This error message should not reference implementation details.
5763
5767
// See: https://github.com/apple/swift/pull/33053#discussion_r477003350
5764
5768
ctx.Diags .diagnose (SourceLoc (), diag::unable_to_convert_generic_swift_types,
5765
- funcName , failedTypesStr);
5769
+ getFuncName () , failedTypesStr);
5766
5770
return nullptr ;
5767
5771
}
5768
5772
@@ -5772,6 +5776,20 @@ clang::FunctionDecl *ClangImporter::instantiateCXXFunctionTemplate(
5772
5776
auto &sema = getClangInstance ().getSema ();
5773
5777
auto *spec = sema.InstantiateFunctionDeclaration (func, templateArgList,
5774
5778
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
+ }
5775
5793
sema.InstantiateFunctionDefinition (clang::SourceLocation (), spec);
5776
5794
return spec;
5777
5795
}
0 commit comments