@@ -6200,8 +6200,32 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
62006200 ClangDirectLookupRequest ({recordDecl, recordDecl->getClangDecl (), name}),
62016201 {});
62026202
6203- // Find the results that are actually a member of "recordDecl" .
6203+ // The set of declarations we found .
62046204 TinyPtrVector<ValueDecl *> result;
6205+ auto addResult = [&result, name](ValueDecl *imported) {
6206+ result.push_back (imported);
6207+
6208+ // Expand any macros introduced by the Clang importer.
6209+ imported->visitAuxiliaryDecls ([&](Decl *decl) {
6210+ auto valueDecl = dyn_cast<ValueDecl>(decl);
6211+ if (!valueDecl)
6212+ return ;
6213+
6214+ // Bail out if the auxiliary decl was not produced by a macro.
6215+ auto module = decl->getDeclContext ()->getParentModule ();
6216+ auto *sf = module ->getSourceFileContainingLocation (decl->getLoc ());
6217+ if (!sf || sf->Kind != SourceFileKind::MacroExpansion)
6218+ return ;
6219+
6220+ // Only produce results that match the requested name.
6221+ if (!valueDecl->getName ().matchesRef (name))
6222+ return ;
6223+
6224+ result.push_back (valueDecl);
6225+ });
6226+ };
6227+
6228+ // Find the results that are actually a member of "recordDecl".
62056229 ClangModuleLoader *clangModuleLoader = ctx.getClangModuleLoader ();
62066230 for (auto foundEntry : directResults) {
62076231 auto found = foundEntry.get <clang::NamedDecl *>();
@@ -6236,7 +6260,8 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
62366260 if (!imported)
62376261 continue ;
62386262 }
6239- result.push_back (cast<ValueDecl>(imported));
6263+
6264+ addResult (cast<ValueDecl>(imported));
62406265 }
62416266
62426267 if (inheritance) {
@@ -6255,7 +6280,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
62556280 if (!imported)
62566281 continue ;
62576282
6258- result. push_back (cast<ValueDecl>( imported) );
6283+ addResult ( imported);
62596284 }
62606285 }
62616286
@@ -6304,7 +6329,7 @@ TinyPtrVector<ValueDecl *> ClangRecordMemberLookup::evaluate(
63046329 if (foundNameArities.count (getArity (foundInBase)))
63056330 continue ;
63066331
6307- result. push_back (foundInBase);
6332+ addResult (foundInBase);
63086333 }
63096334 }
63106335 }
0 commit comments