Skip to content

Commit e0d66c2

Browse files
committed
[C++20] [Modules] Allow export redeclarations within language linkage
Close #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.
1 parent 9c92276 commit e0d66c2

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

clang/lib/Sema/SemaDecl.cpp

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1676,6 +1676,15 @@ bool Sema::CheckRedeclarationExported(NamedDecl *New, NamedDecl *Old) {
16761676
if (IsOldExported)
16771677
return false;
16781678

1679+
// If the Old declaration are not attached to named modules
1680+
// and the New declaration are attached to global module.
1681+
// It should be fine to allow the export since it doesn't change
1682+
// the linkage of declarations. See
1683+
// https://github.com/llvm/llvm-project/issues/98583 for details.
1684+
if (!Old->isInNamedModule() && New->getOwningModule() &&
1685+
New->getOwningModule()->isImplicitGlobalModule())
1686+
return false;
1687+
16791688
assert(IsNewExported);
16801689

16811690
auto Lk = Old->getFormalLinkage();
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// RUN: %clang_cc1 -std=c++20 %s -verify -fsyntax-only
2+
3+
// expected-no-diagnostics
4+
export module mod;
5+
extern "C++" void func();
6+
export extern "C++" {
7+
void func();
8+
}

0 commit comments

Comments
 (0)