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

Chuanqi Xu via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Sun Jan 9 19:39:49 PST 2022


ChuanqiXu created this revision.
ChuanqiXu added reviewers: erichkeane, rjmccall.
ChuanqiXu added a project: clang.
ChuanqiXu requested review of this revision.
Herald added a subscriber: cfe-commits.

This mimics the style of https://github.com/llvm/llvm-project/commit/90010c2e1d60c6a9a4a0b30a113d4dae2b7214eb.

Since ExportDecl and LinkageSpec are transparent DeclContext, they share some similarity. I've checked the test case linked in the revision would fail before this patch.


Repository:
  rG LLVM Github Monorepo

https://reviews.llvm.org/D116911

Files:
  clang/lib/AST/DeclBase.cpp
  clang/test/SemaCXX/lookup-through-export.cpp


Index: clang/test/SemaCXX/lookup-through-export.cpp
===================================================================
--- /dev/null
+++ 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
+}
Index: clang/lib/AST/DeclBase.cpp
===================================================================
--- clang/lib/AST/DeclBase.cpp
+++ clang/lib/AST/DeclBase.cpp
@@ -1212,7 +1212,8 @@
     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;
 }


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D116911.398490.patch
Type: text/x-patch
Size: 1148 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20220110/7833e443/attachment-0001.bin>


More information about the cfe-commits mailing list