[clang] e0d66c2 - [C++20] [Modules] Allow export redeclarations within language linkage
Chuanqi Xu via cfe-commits
cfe-commits at lists.llvm.org
Thu Jul 11 22:58:06 PDT 2024
Author: Chuanqi Xu
Date: 2024-07-12T13:55:56+08:00
New Revision: e0d66c242462d63d99a5324f9799ae5f84f2d84f
URL: https://github.com/llvm/llvm-project/commit/e0d66c242462d63d99a5324f9799ae5f84f2d84f
DIFF: https://github.com/llvm/llvm-project/commit/e0d66c242462d63d99a5324f9799ae5f84f2d84f.diff
LOG: [C++20] [Modules] Allow export redeclarations within language linkage
Close https://github.com/llvm/llvm-project/issues/98583
Currently, clang will reject the following code:
```
export module mod;
extern "C++" void func();
export extern "C++" {
void func();
}
```
while both MSVC and GCC accept it. Although clang's behavior matches the
current wording, from the discussion, the consensus is that we should
accept the above example from the intention. Since the intention to not
allow export redeclaration which is not exported is to make the linkage
clear. But it doesn't matter with the declarations within global module.
Added:
clang/test/Modules/export-redecl-in-language-linkage.cppm
Modified:
clang/lib/Sema/SemaDecl.cpp
Removed:
################################################################################
diff --git a/clang/lib/Sema/SemaDecl.cpp b/clang/lib/Sema/SemaDecl.cpp
index e3377bef2adeb..80b5a8cd4bae6 100644
--- a/clang/lib/Sema/SemaDecl.cpp
+++ b/clang/lib/Sema/SemaDecl.cpp
@@ -1676,6 +1676,15 @@ bool Sema::CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old) {
if (IsOldExported)
return false;
+ // If the Old declaration are not attached to named modules
+ // and the New declaration are attached to global module.
+ // It should be fine to allow the export since it doesn't change
+ // the linkage of declarations. See
+ // https://github.com/llvm/llvm-project/issues/98583 for details.
+ if (!Old->isInNamedModule() && New->getOwningModule() &&
+ New->getOwningModule()->isImplicitGlobalModule())
+ return false;
+
assert(IsNewExported);
auto Lk = Old->getFormalLinkage();
diff --git a/clang/test/Modules/export-redecl-in-language-linkage.cppm b/clang/test/Modules/export-redecl-in-language-linkage.cppm
new file mode 100644
index 0000000000000..c6a4932f5b071
--- /dev/null
+++ b/clang/test/Modules/export-redecl-in-language-linkage.cppm
@@ -0,0 +1,8 @@
+// RUN: %clang_cc1 -std=c++20 %s -verify -fsyntax-only
+
+// expected-no-diagnostics
+export module mod;
+extern "C++" void func();
+export extern "C++" {
+ void func();
+}
More information about the cfe-commits
mailing list