Skip to content

Commit 52d55de

Browse files
committed
Stop reimport of func decl
1 parent 30cb7a2 commit 52d55de

File tree

4 files changed

+22
-3
lines changed

4 files changed

+22
-3
lines changed

lib/ClangImporter/ClangImporter.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4977,7 +4977,7 @@ ValueDecl *cloneBaseMemberDecl(ValueDecl *decl, DeclContext *newContext) {
49774977
// support these we need to tell Swift to type check the synthesized bodies.
49784978
// TODO: we also currently don't support static functions. That shouldn't be
49794979
// too hard.
4980-
if (fn->isStatic() ||
4980+
if (fn->isStatic() || cast<clang::FunctionDecl>(fn->getClangDecl())->isOverloadedOperator() ||
49814981
(fn->getClangDecl() &&
49824982
isa<clang::FunctionTemplateDecl>(fn->getClangDecl())))
49834983
return nullptr;

lib/ClangImporter/ImportDecl.cpp

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4153,6 +4153,13 @@ namespace {
41534153
if (!dc)
41544154
return nullptr;
41554155

4156+
// We may have already imported this function decl before we imported the
4157+
// parent record. In such a case it's important we don't re-import.
4158+
auto known = Impl.ImportedDecls.find({decl, getVersion()});
4159+
if (known != Impl.ImportedDecls.end()) {
4160+
return known->second;
4161+
}
4162+
41564163
bool isOperator = decl->getDeclName().getNameKind() ==
41574164
clang::DeclarationName::CXXOperatorName;
41584165
bool isNonSubscriptOperator =

test/Interop/Cxx/operators/Inputs/member-inline.h

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@ struct AddressOnlyIntWrapper {
4343
int operator()(int x, int y) {
4444
return value + x * y;
4545
}
46+
47+
AddressOnlyIntWrapper operator-(AddressOnlyIntWrapper rhs) const {
48+
return AddressOnlyIntWrapper(value - rhs.value);
49+
}
4650
};
4751

4852
struct HasDeletedOperator {
@@ -274,4 +278,4 @@ struct DerivedFromReadWriteIntArray : ReadWriteIntArray {};
274278

275279
struct DerivedFromNonTrivialArrayByVal : NonTrivialArrayByVal {};
276280

277-
#endif
281+
#endif

test/Interop/Cxx/operators/member-inline.swift

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import StdlibUnittest
88
var OperatorsTestSuite = TestSuite("Operators")
99

1010
#if !os(Windows) // SR-13129
11-
OperatorsTestSuite.test("LoadableIntWrapper.plus (inline)") {
11+
OperatorsTestSuite.test("LoadableIntWrapper.minus (inline)") {
1212
var lhs = LoadableIntWrapper(value: 42)
1313
let rhs = LoadableIntWrapper(value: 23)
1414

@@ -231,6 +231,14 @@ OperatorsTestSuite.test("PtrToPtr.subscript (inline)") {
231231
expectEqual(23, arr[0]![0]![0])
232232
}
233233

234+
OperatorsTestSuite.test("AddressOnlyIntWrapper.minus") {
235+
let lhs = AddressOnlyIntWrapper(42)
236+
let rhs = AddressOnlyIntWrapper(23)
237+
238+
let result = lhs - rhs
239+
expectEqual(19, result.value)
240+
}
241+
234242
// TODO: this causes a crash (does it also crash on main?)
235243
//OperatorsTestSuite.test("TemplatedSubscriptArrayByVal.subscript (inline)") {
236244
// let ptr: UnsafeMutablePointer<Int32> =

0 commit comments

Comments
 (0)