Skip to content

Commit d829636

Browse files
committed
[C++20] [Modules] Don't mark namespace decl as module local declaration
Close llvm#145975 According to [basic.namespace.general]/p2: > A namespace is never attached to a named module and never has a name > with module linkage.
1 parent 4729242 commit d829636

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

clang/lib/AST/DeclBase.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1133,6 +1133,8 @@ bool Decl::isInExportDeclContext() const {
11331133
}
11341134

11351135
bool Decl::isModuleLocal() const {
1136+
if (isa<NamespaceDecl, TranslationUnitDecl>(this))
1137+
return false;
11361138
auto *M = getOwningModule();
11371139
return M && M->isNamedModule() &&
11381140
getModuleOwnershipKind() == ModuleOwnershipKind::ReachableWhenImported;

clang/test/Modules/pr145975.cppm

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir -p %t
3+
// RUN: split-file %s %t
4+
5+
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-module-interface -o %t/b.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-module-interface -o %t/a.pcm \
7+
// RUN: -fmodule-file=a:b=%t/b.pcm
8+
// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-module-interface -o %t/c.pcm \
9+
// RUN: -fmodule-file=a:b=%t/b.pcm -fmodule-file=a=%t/a.pcm
10+
11+
// RUN: %clang_cc1 -std=c++20 %t/b.cppm -emit-reduced-module-interface -o %t/b.pcm
12+
// RUN: %clang_cc1 -std=c++20 %t/a.cppm -emit-reduced-module-interface -o %t/a.pcm \
13+
// RUN: -fmodule-file=a:b=%t/b.pcm
14+
// RUN: %clang_cc1 -std=c++20 %t/c.cppm -emit-reduced-module-interface -o %t/c.pcm \
15+
// RUN: -fmodule-file=a:b=%t/b.pcm -fmodule-file=a=%t/a.pcm
16+
17+
18+
//--- b.cppm
19+
export module a:b;
20+
class Polymorphic {
21+
public:
22+
virtual ~Polymorphic() = default;
23+
};
24+
25+
//--- a.h
26+
namespace std {
27+
using X = int;
28+
}
29+
30+
namespace a {
31+
using std::X;
32+
}
33+
34+
//--- a.cppm
35+
module;
36+
#include "a.h"
37+
export module a;
38+
import :b;
39+
std::X var;
40+
namespace std {
41+
export using std::X;
42+
}
43+
namespace a {
44+
export using std::X;
45+
}
46+
47+
//--- c.cppm
48+
export module c;
49+
import a;
50+
namespace a {
51+
export using std::X;
52+
}
53+
54+
namespace a {
55+
X test() {
56+
return X{};
57+
}
58+
}

0 commit comments

Comments
 (0)