[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.
This commit is contained in:
parent
a69ba0a5f9
commit
e5f196e4e7
@ -3692,12 +3692,6 @@ static void inheritDefaultTemplateArguments(ASTContext &Context,
|
||||
// the program is ill-formed;
|
||||
static void checkMultipleDefinitionInNamedModules(ASTReader &Reader, Decl *D,
|
||||
Decl *Previous) {
|
||||
Module *M = Previous->getOwningModule();
|
||||
|
||||
// We only care about the case in named modules.
|
||||
if (!M || !M->isNamedModule())
|
||||
return;
|
||||
|
||||
// If it is previous implcitly introduced, it is not meaningful to
|
||||
// diagnose it.
|
||||
if (Previous->isImplicit())
|
||||
@ -3714,16 +3708,21 @@ static void checkMultipleDefinitionInNamedModules(ASTReader &Reader, Decl *D,
|
||||
// FIXME: Maybe this shows the implicit instantiations may have incorrect
|
||||
// module owner ships. But given we've finished the compilation of a module,
|
||||
// how can we add new entities to that module?
|
||||
if (auto *VTSD = dyn_cast<VarTemplateSpecializationDecl>(Previous);
|
||||
VTSD && !VTSD->isExplicitSpecialization())
|
||||
if (isa<VarTemplateSpecializationDecl>(Previous))
|
||||
return;
|
||||
if (auto *CTSD = dyn_cast<ClassTemplateSpecializationDecl>(Previous);
|
||||
CTSD && !CTSD->isExplicitSpecialization())
|
||||
if (isa<ClassTemplateSpecializationDecl>(Previous))
|
||||
return;
|
||||
if (auto *Func = dyn_cast<FunctionDecl>(Previous);
|
||||
Func && Func->getTemplateSpecializationInfo())
|
||||
return;
|
||||
|
||||
Module *M = Previous->getOwningModule();
|
||||
if (!M)
|
||||
return;
|
||||
|
||||
// We only forbids merging decls within named modules.
|
||||
if (!M->isNamedModule())
|
||||
return;
|
||||
if (auto *Func = dyn_cast<FunctionDecl>(Previous))
|
||||
if (auto *FTSI = Func->getTemplateSpecializationInfo();
|
||||
FTSI && !FTSI->isExplicitSpecialization())
|
||||
return;
|
||||
|
||||
// It is fine if they are in the same module.
|
||||
if (Reader.getContext().isInSameModule(M, D->getOwningModule()))
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user