Author: Chuanqi Xu Date: 2024-08-09T14:48:56+08:00 New Revision: 8410babc2b69ccb2259e77262ad2baaa17644bea
URL: https://github.com/llvm/llvm-project/commit/8410babc2b69ccb2259e77262ad2baaa17644bea DIFF: https://github.com/llvm/llvm-project/commit/8410babc2b69ccb2259e77262ad2baaa17644bea.diff LOG: [C++20] [Moduels] Correct the linkage of const variable in language linkage from module interfaces (#102574) Close https://github.com/llvm/llvm-project/issues/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. Added: clang/test/Modules/pr99825.cppm Modified: clang/lib/AST/Decl.cpp Removed: ################################################################################ diff --git a/clang/lib/AST/Decl.cpp b/clang/lib/AST/Decl.cpp index d832ce4190ff1a..e125143bc1b270 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<VarTemplateSpecializationDecl>(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 00000000000000..fe6541c6e68e50 --- /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; +} _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits