Skip to content

[C++20] [Moduels] Correct the linkage of const variable in language linkage from module interfaces #102574

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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;
}
Loading