Skip to content

Commit 8410bab

Browse files
authored
[C++20] [Moduels] Correct the linkage of const variable in language linkage from module interfaces (#102574)
Close #99825 The root cause of the issue is that I didn't realize the things in implicit global module (the language linkage in module interfaces) should be considered in module purview.
1 parent 16dadec commit 8410bab

File tree

2 files changed

+15
-7
lines changed

2 files changed

+15
-7
lines changed

clang/lib/AST/Decl.cpp

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -583,12 +583,6 @@ static bool isSingleLineLanguageLinkage(const Decl &D) {
583583
return false;
584584
}
585585

586-
static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) {
587-
if (auto *M = D->getOwningModule())
588-
return M->isInterfaceOrPartition();
589-
return false;
590-
}
591-
592586
static LinkageInfo getExternalLinkageFor(const NamedDecl *D) {
593587
return LinkageInfo::external();
594588
}
@@ -642,7 +636,13 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
642636
// (There is no equivalent in C99.)
643637
if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
644638
!Var->getType().isVolatileQualified() && !Var->isInline() &&
645-
!isDeclaredInModuleInterfaceOrPartition(Var) &&
639+
![Var]() {
640+
// Check if it is module purview except private module fragment
641+
// and implementation unit.
642+
if (auto *M = Var->getOwningModule())
643+
return M->isInterfaceOrPartition() || M->isImplicitGlobalModule();
644+
return false;
645+
}() &&
646646
!isa<VarTemplateSpecializationDecl>(Var) &&
647647
!Var->getDescribedVarTemplate()) {
648648
const VarDecl *PrevVar = Var->getPreviousDecl();

clang/test/Modules/pr99825.cppm

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
2+
// expected-no-diagnostics
3+
export module mod;
4+
5+
extern "C++"
6+
{
7+
export constexpr auto x = 10;
8+
}

0 commit comments

Comments
 (0)