diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index d832ce4190ff1..e125143bc1b27 100644 --- a/clang/lib/AST/Decl.cpp +++ b/clang/lib/AST/Decl.cpp @@ -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(); } @@ -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(Var) && !Var->getDescribedVarTemplate()) { const VarDecl *PrevVar = Var->getPreviousDecl(); diff --git a/clang/test/Modules/pr99825.cppm b/clang/test/Modules/pr99825.cppm new file mode 100644 index 0000000000000..fe6541c6e68e5 --- /dev/null +++ b/clang/test/Modules/pr99825.cppm @@ -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; +}