// - 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();
--- /dev/null
+// 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();
+}
+}