Skip to content

Commit d2e5103

Browse files
committed
[C++20] [Modules] Correct the visibility of decls in implicit global module of other units in the same TU
See the test for the case. It is similar with baa5b76
1 parent a343b8e commit d2e5103

File tree

2 files changed

+21
-1
lines changed

2 files changed

+21
-1
lines changed

clang/lib/Sema/SemaLookup.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1614,7 +1614,7 @@ bool Sema::isUsableModule(const Module *M) {
16141614

16151615
// Otherwise, the global module fragment from other translation unit is not
16161616
// directly usable.
1617-
if (M->isGlobalModule())
1617+
if (M->isExplicitGlobalModule())
16181618
return false;
16191619

16201620
Module *Current = getCurrentModule();
@@ -1628,6 +1628,8 @@ bool Sema::isUsableModule(const Module *M) {
16281628
// module should be visible to the decls in the implicit global module.
16291629
if (Current->isImplicitGlobalModule())
16301630
Current = Current->getTopLevelModule();
1631+
if (M->isImplicitGlobalModule())
1632+
M = M->getTopLevelModule();
16311633

16321634
// If M is the module we're parsing or M and the current module unit lives in
16331635
// the same module, M should be usable.
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
// RUN: rm -rf %t
2+
// RUN: mkdir %t
3+
// RUN: split-file %s %t
4+
//
5+
// RUN: %clang_cc1 -std=c++20 %t/a.interface.cppm -emit-module-interface -o %t/a.pcm
6+
// RUN: %clang_cc1 -std=c++20 %t/a.impl.cc -fmodule-file=a:interface=%t/a.pcm \
7+
// RUN: -verify -fsyntax-only
8+
9+
//--- a.interface.cppm
10+
export module a:interface;
11+
extern "C++" constexpr int a = 43;
12+
13+
//--- a.impl.cc
14+
// expected-no-diagnostics
15+
module a:impl;
16+
import :interface;
17+
static_assert(a == 43);
18+

0 commit comments

Comments
 (0)