[PATCH] D115132: [C++20] [Modules] Namespace Declaration shouldn't have module linkage
Chuanqi Xu via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Tue Dec 7 21:54:54 PST 2021
This revision was landed with ongoing or failed builds.
This revision was automatically updated to reflect the committed changes.
Closed by commit rG60f826663d86: [C++20] [Modules] Namespace Declaration shouldn't have module linkage (authored by ChuanqiXu).
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D115132/new/
https://reviews.llvm.org/D115132
Files:
clang/lib/AST/Decl.cpp
clang/test/CXX/basic/basic.namespace/basic.namespace.general/Inputs/p2.cppm
clang/test/CXX/basic/basic.namespace/basic.namespace.general/Inputs/p2.h
clang/test/CXX/basic/basic.namespace/basic.namespace.general/p2.cppm
Index: clang/test/CXX/basic/basic.namespace/basic.namespace.general/p2.cppm
===================================================================
--- /dev/null
+++ clang/test/CXX/basic/basic.namespace/basic.namespace.general/p2.cppm
@@ -0,0 +1,14 @@
+// Check that the compiler wouldn't crash due to inconsistent namesapce linkage
+// RUN: rm -rf %t
+// RUN: mkdir -p %t
+// RUN: %clang -std=c++20 %S/Inputs/p2.cppm --precompile -o %t/Y.pcm
+// RUN: %clang -std=c++20 -fprebuilt-module-path=%t -I%S/Inputs %s -c -Xclang -verify
+// expected-no-diagnostics
+export module X;
+import Y;
+
+export namespace foo {
+namespace bar{
+ void baz();
+}
+}
Index: clang/test/CXX/basic/basic.namespace/basic.namespace.general/Inputs/p2.h
===================================================================
--- /dev/null
+++ clang/test/CXX/basic/basic.namespace/basic.namespace.general/Inputs/p2.h
@@ -0,0 +1,7 @@
+#ifndef P2_H
+#define P2_H
+namespace foo {
+namespace bar {
+}
+} // namespace foo
+#endif
Index: clang/test/CXX/basic/basic.namespace/basic.namespace.general/Inputs/p2.cppm
===================================================================
--- /dev/null
+++ clang/test/CXX/basic/basic.namespace/basic.namespace.general/Inputs/p2.cppm
@@ -0,0 +1,7 @@
+module;
+#include "p2.h"
+export module Y;
+export namespace foo {
+// We need to export something at least
+void print();
+}
Index: clang/lib/AST/Decl.cpp
===================================================================
--- clang/lib/AST/Decl.cpp
+++ clang/lib/AST/Decl.cpp
@@ -604,8 +604,14 @@
// - A name declared at namespace scope that does not have internal linkage
// by the previous rules and that is introduced by a non-exported
// declaration has module linkage.
- if (isInModulePurview(D) && !isExportedFromModuleInterfaceUnit(
- cast<NamedDecl>(D->getCanonicalDecl())))
+ //
+ // [basic.namespace.general]/p2
+ // A namespace is never attached to a named module and never has a name with
+ // module linkage.
+ if (isInModulePurview(D) &&
+ !isExportedFromModuleInterfaceUnit(
+ cast<NamedDecl>(D->getCanonicalDecl())) &&
+ !isa<NamespaceDecl>(D))
return LinkageInfo(ModuleLinkage, DefaultVisibility, false);
return LinkageInfo::external();
-------------- next part --------------
A non-text attachment was scrubbed...
Name: D115132.392643.patch
Type: text/x-patch
Size: 2305 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20211208/39fe298c/attachment.bin>
More information about the cfe-commits
mailing list