Skip to content

Commit c413a80

Browse files
authored
Merge pull request #67134 from hyp/eng/107561753
[interop] do not import function templates with template parameter no…
2 parents 0d1eca1 + be65796 commit c413a80

File tree

3 files changed

+30
-1
lines changed

3 files changed

+30
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3326,8 +3326,16 @@ namespace {
33263326
// then still add a generic so that it can be overrieded.
33273327
// TODO(https://github.com/apple/swift/issues/57184): In the future we might want to import two overloads in this case so that the default type could still be used.
33283328
if (templateTypeParam->hasDefaultArgument() &&
3329-
!templateParamTypeUsedInSignature(templateTypeParam))
3329+
!templateParamTypeUsedInSignature(templateTypeParam)) {
3330+
// We do not yet support instantiation of default values of template
3331+
// parameters when the function template is instantiated, so do not
3332+
// import the function template if the template parameter has
3333+
// dependent default value.
3334+
auto defaultArgumentType = templateTypeParam->getDefaultArgument();
3335+
if (defaultArgumentType->isDependentType())
3336+
return nullptr;
33303337
continue;
3338+
}
33313339

33323340
auto *typeParam = Impl.createDeclWithClangNode<GenericTypeParamDecl>(
33333341
param, AccessLevel::Public, dc,

test/Interop/Cxx/templates/Inputs/enable-if.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,4 +26,14 @@ struct HasMethodWithEnableIf {
2626
}
2727
};
2828

29+
struct HasConstructorWithEnableIf {
30+
template<class T, class _ = typename enable_if<is_bool<T>::value, bool>::type>
31+
HasConstructorWithEnableIf(const T &);
32+
};
33+
34+
struct HasConstructorWithEnableIfUsed {
35+
template<class T, class U = typename enable_if<is_bool<T>::value, bool>::type>
36+
HasConstructorWithEnableIfUsed(const T &, const U &);
37+
};
38+
2939
#endif // TEST_INTEROP_CXX_TEMPLATES_INPUTS_ENABLE_IF_H
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// RUN: %target-swift-ide-test -print-module -module-to-print=EnableIf -I %S/Inputs -source-filename=x -enable-experimental-cxx-interop | %FileCheck %s
2+
3+
// The `init<T>` constructor template is not yet supported in Swift.
4+
5+
// CHECK: struct HasConstructorWithEnableIf {
6+
// CHECK-NEXT: @available(*, deprecated, message: "This zero-initializes the backing memory of the struct, which is unsafe for some C++ structs. Consider adding an explicit default initializer for this C++ struct.")
7+
// CHECK-NEXT: init()
8+
// CHECK-NEXT:}
9+
10+
// CHECK: struct HasConstructorWithEnableIfUsed {
11+
// CHECK-NEXT: init<T, U>(_: T, _: U)

0 commit comments

Comments
 (0)