[AST] Don't consider 'ExportDecl' when calculating DeclContext 'Encloses'

This mimics the style of 90010c2e1 (Don't consider 'LinkageSpec' when
calculating DeclContext 'Encloses'). Since ExportDecl and LinkageSpec
are transparent DeclContext, they share some similarity.

Reviewed By: erichkeane

Differential Revision: https://reviews.llvm.org/D116911
This commit is contained in:
Chuanqi Xu 2022-01-11 09:54:57 +08:00
parent 63f0c00d38
commit 86c5b870b2
2 changed files with 33 additions and 1 deletions

View File

@ -1212,7 +1212,8 @@ bool DeclContext::Encloses(const DeclContext *DC) const {
return getPrimaryContext()->Encloses(DC);
for (; DC; DC = DC->getParent())
if (!isa<LinkageSpecDecl>(DC) && DC->getPrimaryContext() == this)
if (!isa<LinkageSpecDecl>(DC) && !isa<ExportDecl>(DC) &&
DC->getPrimaryContext() == this)
return true;
return false;
}

View File

@ -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
}