From 86c5b870b2e5192a9414204500a53b31524db065 Mon Sep 17 00:00:00 2001 From: Chuanqi Xu Date: Tue, 11 Jan 2022 09:54:57 +0800 Subject: [PATCH] [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 --- clang/lib/AST/DeclBase.cpp | 3 +- clang/test/SemaCXX/lookup-through-export.cpp | 31 ++++++++++++++++++++ 2 files changed, 33 insertions(+), 1 deletion(-) create mode 100644 clang/test/SemaCXX/lookup-through-export.cpp 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 +}