Skip to content

[cxx-interop] Support function templates inside a namespace. #34607

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions lib/ClangImporter/ImportDecl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3732,7 +3732,8 @@ namespace {
ParameterList *getNonSelfParamList(
DeclContext *dc, const clang::FunctionDecl *decl,
Optional<unsigned> selfIdx, ArrayRef<Identifier> argNames,
bool allowNSUIntegerAsInt, bool isAccessor) {
bool allowNSUIntegerAsInt, bool isAccessor,
ArrayRef<GenericTypeParamDecl *> genericParams) {
if (bool(selfIdx)) {
assert(((decl->getNumParams() == argNames.size() + 1) || isAccessor) &&
(*selfIdx < decl->getNumParams()) && "where's self?");
Expand All @@ -3748,7 +3749,7 @@ namespace {
}
return Impl.importFunctionParameterList(
dc, decl, nonSelfParams, decl->isVariadic(), allowNSUIntegerAsInt,
argNames, /*genericParams=*/{});
argNames, genericParams);
}

Decl *importGlobalAsInitializer(const clang::FunctionDecl *decl,
Expand Down Expand Up @@ -3886,7 +3887,7 @@ namespace {

bodyParams =
getNonSelfParamList(dc, decl, selfIdx, name.getArgumentNames(),
allowNSUIntegerAsInt, !name);
allowNSUIntegerAsInt, !name, templateParams);

importedType =
Impl.importFunctionReturnType(dc, decl, allowNSUIntegerAsInt);
Expand Down
13 changes: 13 additions & 0 deletions test/Interop/Cxx/templates/Inputs/function-templates.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,3 +52,16 @@ template <class T> void lvalueReference(T &ref) { ref = 42; }
template <class T> void constLvalueReference(const T &) {}

template <class T> void forwardingReference(T &&) {}

namespace Orbiters {

template<class T>
void galileo(T) { }

template<class T, class U>
void cassini(T, U) { }

template<class T>
void magellan(T&) { }

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,13 @@
// CHECK: func passThroughConst<T>(_ value: T) -> T
// CHECK: func returns_template<R, T, U>(_ a: T, _ b: U) -> R
// CHECK: func cannot_infer_template<T>()

// CHECK: func lvalueReference<T>(_ ref: UnsafeMutablePointer<T>)
// CHECK: func constLvalueReference<T>(_: UnsafePointer<T>)
// CHECK: func forwardingReference<T>(_: UnsafeMutablePointer<T>)

// CHECK: enum Orbiters {
// CHECK: static func galileo<T>(_: T)
// CHECK: static func cassini<T, U>(_: T, _: U)
// CHECK: static func magellan<T>(_: UnsafeMutablePointer<T>)
// CHECK: }