Skip to content

Commit 0d728ee

Browse files
authored
Merge pull request #34863 from zoecarver/cxx/fix/variadic-members
[cxx-interop] Fix assertion to allow variadic members.
2 parents 3cb6940 + 3d6c8a7 commit 0d728ee

File tree

3 files changed

+15
-1
lines changed

3 files changed

+15
-1
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3738,7 +3738,9 @@ namespace {
37383738
assert(((decl->getNumParams() == argNames.size() + 1) || isAccessor) &&
37393739
(*selfIdx < decl->getNumParams()) && "where's self?");
37403740
} else {
3741-
assert(decl->getNumParams() == argNames.size() || isAccessor);
3741+
unsigned numParamsAdjusted =
3742+
decl->getNumParams() + (decl->isVariadic() ? 1 : 0);
3743+
assert(numParamsAdjusted == argNames.size() || isAccessor);
37423744
}
37433745

37443746
SmallVector<const clang::ParmVarDecl *, 4> nonSelfParams;

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ template <class R, class T, class U> R returns_template(T a, U b) {
2121
// Same here:
2222
template <class T> void cannot_infer_template() {}
2323

24+
struct HasVariadicMemeber {
25+
void test1(...) {}
26+
void test2(int, ...) {}
27+
};
28+
2429
// TODO: We should support these types. Until then, make sure we don't crash when importing.
2530
template<class... Ts>
2631
void testPackExpansion(Ts...) { }

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

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,13 @@
77
// CHECK: func returns_template<R, T, U>(_ a: T, _ b: U) -> R
88
// CHECK: func cannot_infer_template<T>()
99

10+
// CHECK: struct HasVariadicMemeber {
11+
// CHECK: @available(*, unavailable, message: "Variadic function is unavailable")
12+
// CHECK: mutating func test1(_ varargs: Any...)
13+
// CHECK: @available(*, unavailable, message: "Variadic function is unavailable")
14+
// CHECK: mutating func test2(_: Int32, _ varargs: Any...)
15+
// CHECK: }
16+
1017
// CHECK: func lvalueReference<T>(_ ref: UnsafeMutablePointer<T>)
1118
// CHECK: func constLvalueReference<T>(_: UnsafePointer<T>)
1219
// CHECK: func forwardingReference<T>(_: UnsafeMutablePointer<T>)

0 commit comments

Comments
 (0)