Skip to content

Commit 0c1b431

Browse files
committed
SR-12802: Disambiguate functions with lvalue and rvalue reference parameters in the same overload set
1 parent c88a157 commit 0c1b431

File tree

3 files changed

+12
-15
lines changed

3 files changed

+12
-15
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2291,9 +2291,10 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
22912291
return nullptr;
22922292
}
22932293

2294-
paramTy = refType->getPointeeType();
2295-
if (!paramTy.isConstQualified())
2296-
isInOut = true;
2294+
paramTy = refType->getPointeeType();
2295+
if (isa<clang::LValueReferenceType>(paramTy) && !paramTy.isConstQualified()) {
2296+
isInOut = true;
2297+
}
22972298
}
22982299

22992300
if (!swiftParamTy) {

test/Interop/Cxx/stdlib/use-std-iterator.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,9 @@ var StdIteratorTestSuite = TestSuite("StdIterator")
1313

1414
StdIteratorTestSuite.test("init") {
1515
var vector = Vector()
16-
var _1: CInt = 1
1716
//There seems to be an issue when importing this method, where the const_ref is mapped with
1817
//the correct typealias to be able to pass immutable values. related to: https://github.com/apple/swift/pull/41611
19-
vector.push_back(&_1)
18+
vector.push_back(1)
2019
//ideally we should call vector.begin(), however we need to prevent a copy of self before vector.begin() is invoked
2120
//current workaround is to use beginMutating()
2221
let it = vector.beginMutating()
@@ -25,10 +24,9 @@ StdIteratorTestSuite.test("init") {
2524

2625
StdIteratorTestSuite.test("advance") {
2726
var vector = Vector()
28-
var _1: CInt = 1, _2: CInt = 2, _3: CInt = 3
29-
vector.push_back(&_1)
30-
vector.push_back(&_2)
31-
vector.push_back(&_3)
27+
vector.push_back(1)
28+
vector.push_back(2)
29+
vector.push_back(3)
3230
var it = vector.beginMutating()
3331
std.__1.advance(&it, 2)
3432
expectEqual(it[0], 3)

test/Interop/Cxx/stdlib/use-std-vector.swift

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,16 @@ StdVectorTestSuite.test("init") {
2424

2525
StdVectorTestSuite.test("push back") {
2626
var v = Vector()
27-
var _42: CInt = 42
28-
v.push_back(&_42)
27+
v.push_back(42)
2928
expectEqual(v.size(), 1)
3029
expectFalse(v.empty())
3130
expectEqual(v[0], 42)
3231
}
3332

3433
func fill(vector v: inout Vector) {
35-
var _1: CInt = 1, _2: CInt = 2, _3: CInt = 3
36-
v.push_back(&_1)
37-
v.push_back(&_2)
38-
v.push_back(&_3)
34+
v.push_back(1)
35+
v.push_back(2)
36+
v.push_back(3)
3937
}
4038

4139
// TODO: in some configurations the stdlib emits a "initializeWithCopy" where the arguments

0 commit comments

Comments
 (0)