@@ -142,7 +142,7 @@ static ValueDecl *lookupOperator(NominalTypeDecl *decl, Identifier id,
142142
143143 // If no member operator was found, look for out-of-class definitions in the
144144 // same module.
145- auto module = decl->getModuleContext ();
145+ auto module = decl->getModuleContextForNameLookup ();
146146 SmallVector<ValueDecl *> nonMemberResults;
147147 module ->lookupValue (id, NLKind::UnqualifiedLookup, nonMemberResults);
148148 for (const auto &nonMember : nonMemberResults) {
@@ -273,8 +273,17 @@ instantiateTemplatedOperator(ClangImporter::Implementation &impl,
273273 best)) {
274274 case clang::OR_Success: {
275275 if (auto clangCallee = best->Function ) {
276- auto lookupTable = impl.findLookupTable (classDecl);
277- addEntryToLookupTable (*lookupTable, clangCallee, impl.getNameImporter ());
276+ // Declarations inside of a C++ namespace are added into two lookup
277+ // tables: one for the __ObjC module, one for the actual owning Clang
278+ // module of the decl. This is a hack that is meant to address the case
279+ // when a namespace spans across multiple Clang modules. Mimic that
280+ // behavior for the operator that we just instantiated.
281+ auto lookupTable1 = impl.findLookupTable (classDecl);
282+ addEntryToLookupTable (*lookupTable1, clangCallee, impl.getNameImporter ());
283+ auto owningModule = impl.getClangOwningModule (classDecl);
284+ auto lookupTable2 = impl.findLookupTable (owningModule);
285+ if (lookupTable1 != lookupTable2)
286+ addEntryToLookupTable (*lookupTable2, clangCallee, impl.getNameImporter ());
278287 return clangCallee;
279288 }
280289 break ;
@@ -377,8 +386,13 @@ static bool synthesizeCXXOperator(ClangImporter::Implementation &impl,
377386 equalEqualDecl->setBody (equalEqualBody);
378387
379388 impl.synthesizedAndAlwaysVisibleDecls .insert (equalEqualDecl);
380- auto lookupTable = impl.findLookupTable (classDecl);
381- addEntryToLookupTable (*lookupTable, equalEqualDecl, impl.getNameImporter ());
389+ auto lookupTable1 = impl.findLookupTable (classDecl);
390+ addEntryToLookupTable (*lookupTable1, equalEqualDecl, impl.getNameImporter ());
391+ auto owningModule = impl.getClangOwningModule (classDecl);
392+ auto lookupTable2 = impl.findLookupTable (owningModule);
393+ if (lookupTable1 != lookupTable2)
394+ addEntryToLookupTable (*lookupTable2, equalEqualDecl,
395+ impl.getNameImporter ());
382396 return true ;
383397}
384398
0 commit comments