diff --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp index 064012ba865c..52b8a4572110 100644 --- a/clang/lib/AST/DeclBase.cpp +++ b/clang/lib/AST/DeclBase.cpp @@ -1212,7 +1212,8 @@ bool DeclContext::Encloses(const DeclContext *DC) const { return getPrimaryContext()->Encloses(DC); for (; DC; DC = DC->getParent()) - if (!isa(DC) && DC->getPrimaryContext() == this) + if (!isa(DC) && !isa(DC) && + DC->getPrimaryContext() == this) return true; return false; } diff --git a/clang/test/SemaCXX/lookup-through-export.cpp b/clang/test/SemaCXX/lookup-through-export.cpp new file mode 100644 index 000000000000..503a69465560 --- /dev/null +++ b/clang/test/SemaCXX/lookup-through-export.cpp @@ -0,0 +1,31 @@ +// RUN: %clang_cc1 -std=c++20 %s -verify + +// expected-no-diagnostics +export module X; +export { + namespace A { + namespace B { + int bar; + } + } // namespace A + namespace C { + void foo() { + using namespace A; + (void)B::bar; + } + } // namespace C +} + +export { + namespace D { + namespace E { + int bar; + } + } // namespace D + namespace F { + void foo() { + using namespace D; + (void)E::bar; + } + } // namespace F +}