Index: clang/include/clang/AST/DeclBase.h =================================================================== --- clang/include/clang/AST/DeclBase.h +++ clang/include/clang/AST/DeclBase.h @@ -1142,6 +1142,11 @@ /// that are missing from the lookup table. mutable bool HasLazyExternalLexicalLookups : 1; + /// \brief If \c true, lookups should only return identifier from + /// DeclContext scope (for example TranslationUnit). Used in + /// LookupQualifiedName() + mutable bool UseQualifiedLookup : 1; + /// \brief Pointer to the data structure used to lookup declarations /// within this context (or a DependentStoredDeclsMap if this is a /// dependent context). We maintain the invariant that, if the map @@ -1176,6 +1181,7 @@ ExternalVisibleStorage(false), NeedToReconcileExternalVisibleStorage(false), HasLazyLocalLexicalLookups(false), HasLazyExternalLexicalLookups(false), + UseQualifiedLookup(false), LookupPtr(nullptr), FirstDecl(nullptr), LastDecl(nullptr) {} public: @@ -1756,6 +1762,16 @@ D == LastDecl); } + bool setUseQualifiedLookup(bool use = true) { + bool old_value = UseQualifiedLookup; + UseQualifiedLookup = use; + return old_value; + } + + bool shouldUseQualifiedLookup() const { + return UseQualifiedLookup; + } + static bool classof(const Decl *D); static bool classof(const DeclContext *D) { return true; } Index: clang/lib/Sema/SemaLookup.cpp =================================================================== --- clang/lib/Sema/SemaLookup.cpp +++ clang/lib/Sema/SemaLookup.cpp @@ -204,6 +204,13 @@ UnqualUsingEntry::Comparator())); } }; + + class Deinitializer { + std::function Deinit; + public: + Deinitializer(const std::function& d): Deinit(d) {} + ~Deinitializer() { Deinit(); } + }; } // Retrieve the set of identifier namespaces that correspond to a @@ -1852,6 +1859,9 @@ "Declaration context must already be complete!"); // Perform qualified name lookup into the LookupCtx. + bool oldval = LookupCtx->setUseQualifiedLookup(); + Deinitializer deinit([&]() { LookupCtx->setUseQualifiedLookup(oldval); }); + if (LookupDirect(*this, R, LookupCtx)) { R.resolveKind(); if (isa(LookupCtx))