Author: Chuanqi Xu
Date: 2025-06-27T13:35:09+08:00
New Revision: d829636f5d71d8a3771d9f96f22f1fe7507a32ec

URL: 
https://github.com/llvm/llvm-project/commit/d829636f5d71d8a3771d9f96f22f1fe7507a32ec
DIFF: 
https://github.com/llvm/llvm-project/commit/d829636f5d71d8a3771d9f96f22f1fe7507a32ec.diff

LOG: [C++20] [Modules] Don't mark namespace decl as module local declaration

Close https://github.com/llvm/llvm-project/issues/145975

According to [basic.namespace.general]/p2:
> A namespace is never attached to a named module and never has a name
> with module linkage.

Added: 
    clang/test/Modules/pr145975.cppm

Modified: 
    clang/lib/AST/DeclBase.cpp

Removed: 
    


################################################################################
diff  --git a/clang/lib/AST/DeclBase.cpp b/clang/lib/AST/DeclBase.cpp
index 48c60aa4e449a..13c46fdbff96a 100644
--- a/clang/lib/AST/DeclBase.cpp
+++ b/clang/lib/AST/DeclBase.cpp
@@ -1133,6 +1133,8 @@ bool Decl::isInExportDeclContext() const {
 }
 
 bool Decl::isModuleLocal() const {
+  if (isa<NamespaceDecl, TranslationUnitDecl>(this))
+    return false;
   auto *M = getOwningModule();
   return M && M->isNamedModule() &&
          getModuleOwnershipKind() == 
ModuleOwnershipKind::ReachableWhenImported;

diff  --git a/clang/test/Modules/pr145975.cppm 
b/clang/test/Modules/pr145975.cppm
new file mode 100644
index 0000000000000..792c4ad811a15
--- /dev/null
+++ b/clang/test/Modules/pr145975.cppm
@@ -0,0 +1,58 @@
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: split-file %s %t
+
+// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm \
+// RUN:     -fmodule-file=a:b=%t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface -o %t/c.pcm \
+// RUN:     -fmodule-file=a:b=%t/b.pcm -fmodule-file=a=%t/a.pcm
+
+// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o 
%t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o 
%t/a.pcm \
+// RUN:     -fmodule-file=a:b=%t/b.pcm
+// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-reduced-module-interface -o 
%t/c.pcm \
+// RUN:     -fmodule-file=a:b=%t/b.pcm -fmodule-file=a=%t/a.pcm
+
+
+//--- b.cppm
+export module a:b;
+class Polymorphic {
+public:
+    virtual ~Polymorphic() = default;
+};
+
+//--- a.h
+namespace std {
+using X = int;
+}
+
+namespace a {
+    using std::X;
+}
+
+//--- a.cppm
+module;
+#include "a.h"
+export module a;
+import :b;
+std::X var;
+namespace std {
+    export using std::X;
+}
+namespace a {
+    export using std::X;
+}
+
+//--- c.cppm
+export module c;
+import a;
+namespace a {
+    export using std::X;
+}
+
+namespace a {
+    X test() {
+        return X{};
+    }
+}


        
_______________________________________________
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits

Reply via email to