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


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;
 }
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
  • [PATCH] D116911: [AST] Don't co... Chuanqi Xu via Phabricator via cfe-commits

Reply via email to