Skip to content

Commit ad545f8

Browse files
authored
Merge pull request #34607 from zoecarver/cxx/fix/function-template-in-namespace
[cxx-interop] Support function templates inside a namespace.
2 parents cd9218c + 9c58a95 commit ad545f8

File tree

3 files changed

+24
-3
lines changed

3 files changed

+24
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3732,7 +3732,8 @@ namespace {
37323732
ParameterList *getNonSelfParamList(
37333733
DeclContext *dc, const clang::FunctionDecl *decl,
37343734
Optional<unsigned> selfIdx, ArrayRef<Identifier> argNames,
3735-
bool allowNSUIntegerAsInt, bool isAccessor) {
3735+
bool allowNSUIntegerAsInt, bool isAccessor,
3736+
ArrayRef<GenericTypeParamDecl *> genericParams) {
37363737
if (bool(selfIdx)) {
37373738
assert(((decl->getNumParams() == argNames.size() + 1) || isAccessor) &&
37383739
(*selfIdx < decl->getNumParams()) && "where's self?");
@@ -3748,7 +3749,7 @@ namespace {
37483749
}
37493750
return Impl.importFunctionParameterList(
37503751
dc, decl, nonSelfParams, decl->isVariadic(), allowNSUIntegerAsInt,
3751-
argNames, /*genericParams=*/{});
3752+
argNames, genericParams);
37523753
}
37533754

37543755
Decl *importGlobalAsInitializer(const clang::FunctionDecl *decl,
@@ -3886,7 +3887,7 @@ namespace {
38863887

38873888
bodyParams =
38883889
getNonSelfParamList(dc, decl, selfIdx, name.getArgumentNames(),
3889-
allowNSUIntegerAsInt, !name);
3890+
allowNSUIntegerAsInt, !name, templateParams);
38903891

38913892
importedType =
38923893
Impl.importFunctionReturnType(dc, decl, allowNSUIntegerAsInt);

test/Interop/Cxx/templates/Inputs/function-templates.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,3 +52,16 @@ template <class T> void lvalueReference(T &ref) { ref = 42; }
5252
template <class T> void constLvalueReference(const T &) {}
5353

5454
template <class T> void forwardingReference(T &&) {}
55+
56+
namespace Orbiters {
57+
58+
template<class T>
59+
void galileo(T) { }
60+
61+
template<class T, class U>
62+
void cassini(T, U) { }
63+
64+
template<class T>
65+
void magellan(T&) { }
66+
67+
}

test/Interop/Cxx/templates/function-template-module-interface.swift

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,13 @@
66
// CHECK: func passThroughConst<T>(_ value: T) -> T
77
// CHECK: func returns_template<R, T, U>(_ a: T, _ b: U) -> R
88
// CHECK: func cannot_infer_template<T>()
9+
910
// CHECK: func lvalueReference<T>(_ ref: UnsafeMutablePointer<T>)
1011
// CHECK: func constLvalueReference<T>(_: UnsafePointer<T>)
1112
// CHECK: func forwardingReference<T>(_: UnsafeMutablePointer<T>)
13+
14+
// CHECK: enum Orbiters {
15+
// CHECK: static func galileo<T>(_: T)
16+
// CHECK: static func cassini<T, U>(_: T, _: U)
17+
// CHECK: static func magellan<T>(_: UnsafeMutablePointer<T>)
18+
// CHECK: }

0 commit comments

Comments
 (0)