Skip to content

Commit e5f196e

Browse files
committed
[NFCI] [C++20] [Modules] Relax the case for duplicated declaration in multiple module units for explicit specialization
Relax the case for duplicated declaration in multiple module units for explicit specialization and refactor the implementation of checkMultipleDefinitionInNamedModules a little bit. This is intended to not affect any end users since it only relaxes the condition to emit an error.
1 parent a69ba0a commit e5f196e

File tree

1 file changed

+13
-14
lines changed

1 file changed

+13
-14
lines changed

clang/lib/Serialization/ASTReaderDecl.cpp

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3692,12 +3692,6 @@ static void inheritDefaultTemplateArguments(ASTContext &Context,
36923692
// the program is ill-formed;
36933693
static void checkMultipleDefinitionInNamedModules(ASTReader &Reader, Decl *D,
36943694
Decl *Previous) {
3695-
Module *M = Previous->getOwningModule();
3696-
3697-
// We only care about the case in named modules.
3698-
if (!M || !M->isNamedModule())
3699-
return;
3700-
37013695
// If it is previous implcitly introduced, it is not meaningful to
37023696
// diagnose it.
37033697
if (Previous->isImplicit())
@@ -3714,16 +3708,21 @@ static void checkMultipleDefinitionInNamedModules(ASTReader &Reader, Decl *D,
37143708
// FIXME: Maybe this shows the implicit instantiations may have incorrect
37153709
// module owner ships. But given we've finished the compilation of a module,
37163710
// how can we add new entities to that module?
3717-
if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Previous);
3718-
VTSD && !VTSD->isExplicitSpecialization())
3711+
if (isa<VarTemplateSpecializationDecl>(Previous))
37193712
return;
3720-
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Previous);
3721-
CTSD && !CTSD->isExplicitSpecialization())
3713+
if (isa<ClassTemplateSpecializationDecl>(Previous))
3714+
return;
3715+
if (auto *Func = dyn_cast<FunctionDecl>(Previous);
3716+
Func && Func->getTemplateSpecializationInfo())
3717+
return;
3718+
3719+
Module *M = Previous->getOwningModule();
3720+
if (!M)
3721+
return;
3722+
3723+
// We only forbids merging decls within named modules.
3724+
if (!M->isNamedModule())
37223725
return;
3723-
if (auto *Func = dyn_cast<FunctionDecl>(Previous))
3724-
if (auto *FTSI = Func->getTemplateSpecializationInfo();
3725-
FTSI && !FTSI->isExplicitSpecialization())
3726-
return;
37273726

37283727
// It is fine if they are in the same module.
37293728
if (Reader.getContext().isInSameModule(M, D->getOwningModule()))

0 commit comments

Comments
 (0)