Skip to content

Commit

Permalink
[C++20] [Moduels] Correct the linkage of const variable in language l…
Browse files Browse the repository at this point in the history
…inkage 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.
  • Loading branch information
ChuanqiXu9 authored Aug 9, 2024
1 parent 16dadec commit 8410bab
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 7 deletions.
14 changes: 7 additions & 7 deletions clang/lib/AST/Decl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -583,12 +583,6 @@ static bool isSingleLineLanguageLinkage(const Decl &D) {
return false;
}

static bool isDeclaredInModuleInterfaceOrPartition(const NamedDecl *D) {
if (auto *M = D->getOwningModule())
return M->isInterfaceOrPartition();
return false;
}

static LinkageInfo getExternalLinkageFor(const NamedDecl *D) {
return LinkageInfo::external();
}
Expand Down Expand Up @@ -642,7 +636,13 @@ LinkageComputer::getLVForNamespaceScopeDecl(const NamedDecl *D,
// (There is no equivalent in C99.)
if (Context.getLangOpts().CPlusPlus && Var->getType().isConstQualified() &&
!Var->getType().isVolatileQualified() && !Var->isInline() &&
!isDeclaredInModuleInterfaceOrPartition(Var) &&
![Var]() {
// Check if it is module purview except private module fragment
// and implementation unit.
if (auto *M = Var->getOwningModule())
return M->isInterfaceOrPartition() || M->isImplicitGlobalModule();
return false;
}() &&
!isa<VarTemplateSpecializationDecl>(Var) &&
!Var->getDescribedVarTemplate()) {
const VarDecl *PrevVar = Var->getPreviousDecl();
Expand Down
8 changes: 8 additions & 0 deletions clang/test/Modules/pr99825.cppm
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// RUN: %clang_cc1 -std=c++20 %s -fsyntax-only -verify
// expected-no-diagnostics
export module mod;

extern "C++"
{
export constexpr auto x = 10;
}

0 comments on commit 8410bab

Please sign in to comment.