Skip to content

Commit 3816ee9

Browse files
committed
SR-12802: Disambiguate functions with lvalue and rvalue reference parameters in the same overload set
1 parent db7d1e7 commit 3816ee9

File tree

5 files changed

+31
-18
lines changed

5 files changed

+31
-18
lines changed

lib/ClangImporter/ImportType.cpp

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2312,9 +2312,11 @@ ParameterList *ClangImporter::Implementation::importFunctionParameterList(
23122312
return nullptr;
23132313
}
23142314

2315-
paramTy = refType->getPointeeType();
2316-
if (!paramTy.isConstQualified())
2317-
isInOut = true;
2315+
paramTy = refType->getPointeeType();
2316+
if (isa<clang::LValueReferenceType>(paramTy)
2317+
&& !paramTy.isConstQualified()) {
2318+
isInOut = true;
2319+
}
23182320
}
23192321

23202322
if (!swiftParamTy) {

lib/SIL/IR/SILFunctionType.cpp

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1328,9 +1328,22 @@ static bool isClangTypeMoreIndirectThanSubstType(TypeConverter &TC,
13281328
// Pass C++ const reference types indirectly. Right now there's no way to
13291329
// express immutable borrowed params, so we have to have this hack.
13301330
// Eventually, we should just express these correctly: rdar://89647503
1331-
if (clangTy->isReferenceType() &&
1332-
clangTy->getPointeeType().isConstQualified())
1333-
return true;
1331+
1332+
/*
1333+
Why does this not compile?
1334+
if (clangTy->getPointeeType().isConstQualified() ||
1335+
clangTy->isRValueReferenceType()) {
1336+
1337+
return true;
1338+
}
1339+
*/
1340+
if (clangTy->isReferenceType()) {
1341+
if (clangTy->getPointeeType().isConstQualified() ||
1342+
clangTy->isRValueReferenceType()) {
1343+
1344+
return true;
1345+
}
1346+
}
13341347

13351348
return false;
13361349
}

test/Interop/Cxx/class/method/ambiguous-methods-module-interface.swift

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,11 @@
33
// CHECK: func increment(_ a: Int32) -> Int32
44
// CHECK: mutating func incrementMutating(_ a: Int32) -> Int32
55

6-
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32, _ c: inout Int32)
7-
// CHECK: func increment(_ a: Int32, _ b: Int32, _ c: inout Int32)
6+
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32, _ c: Int32)
7+
// CHECK: func increment(_ a: Int32, _ b: Int32, _ c: Int32)
88

9-
// CHECK: mutating func incrementMutating(_ a: inout Int32, _ b: Int32)
10-
// CHECK: func increment(_ a: inout Int32, _ b: Int32)
9+
// CHECK: mutating func incrementMutating(_ a: Int32, _ b: Int32)
10+
// CHECK: func increment(_ a: Int32, _ b: Int32)
1111

1212
// CHECK: func numberOfMutableMethodsCalled() -> Int32
1313
// CHECK: mutating func numberOfMutableMethodsCalledMutating() -> Int32

test/Interop/Cxx/reference/reference-irgen.swift

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ public func getConstCxxRvalueRef() -> UnsafePointer<CInt> {
3232

3333
public func setCxxRef() {
3434
var val: CInt = 21
35-
setStaticIntRef(&val)
35+
setStaticIntRef(val)
3636
}
3737

3838
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main9setCxxRefyyF"()
@@ -48,7 +48,7 @@ public func setCxxConstRef() {
4848

4949
public func setCxxRvalueRef() {
5050
var val: CInt = 21
51-
setStaticIntRvalueRef(&val)
51+
setStaticIntRvalueRef(val)
5252
}
5353

5454
// CHECK: define {{(protected |dllexport )?}}swiftcc void @"$s4main15setCxxRvalueRefyyF"()

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)