Skip to content

Commit 0b69eb5

Browse files
committed
[cxx-interop] Refactor: add member operator instantiations to the lookup table elsewhere
NFC intended
1 parent 98e65d0 commit 0b69eb5

File tree

1 file changed

+15
-3
lines changed

1 file changed

+15
-3
lines changed

lib/ClangImporter/ImportDecl.cpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2339,9 +2339,6 @@ namespace {
23392339

23402340
// Make sure the synthesized decl can be found by lookupDirect.
23412341
result->addMemberToLookupTable(opFuncDecl);
2342-
2343-
addEntryToLookupTable(*Impl.findLookupTable(decl), cxxMethod,
2344-
Impl.getNameImporter());
23452342
}
23462343
}
23472344
methods.push_back(MD);
@@ -3005,6 +3002,21 @@ namespace {
30053002
if (isSpecializationDepthGreaterThan(def, 8))
30063003
return nullptr;
30073004

3005+
// For class template instantiations, we need to add their member
3006+
// operators to the lookup table to make them discoverable with
3007+
// unqualified lookup. This makes it possible to implement a Swift
3008+
// protocol requirement with an instantiation of a C++ member operator.
3009+
// This cannot be done when building the lookup table,
3010+
// because templates are instantiated lazily.
3011+
for (auto member : def->decls()) {
3012+
if (auto method = dyn_cast<clang::CXXMethodDecl>(member)) {
3013+
if (method->isOverloadedOperator()) {
3014+
addEntryToLookupTable(*Impl.findLookupTable(decl), method,
3015+
Impl.getNameImporter());
3016+
}
3017+
}
3018+
}
3019+
30083020
return VisitCXXRecordDecl(def);
30093021
}
30103022

0 commit comments

Comments
 (0)