Closed martong closed 5 years ago
There is an other case where we should call HandleNameConflict
in VisitClassTemplateSpecializationDecl
:
if (isStructuralMatch(D, PrevDecl)) {
if (D->isThisDeclarationADefinition() && PrevDecl->getDefinition()) {
Importer.MapImported(D, PrevDecl->getDefinition());
// Import those those default field initializers which have been
// instantiated in the "From" context, but not in the "To" context.
for (auto *FromField : D->fields()) {
auto ToOrErr = import(FromField);
if (!ToOrErr)
// FIXME: return the error?
consumeError(ToOrErr.takeError());
}
// Import those methods which have been instantiated in the
// "From" context, but not in the "To" context.
for (CXXMethodDecl *FromM : D->methods()) {
auto ToOrErr = import(FromM);
if (!ToOrErr)
// FIXME: return the error?
consumeError(ToOrErr.takeError());
}
// TODO Import instantiated default arguments.
// TODO Import instantiated exception specifications.
//
// Generally, ASTCommon.h/DeclUpdateKind enum gives a very good hint
// what
// else could be fused during an AST merge.
return PrevDecl;
}
} else { // ODR violation.
// HERE WE SHOULD CALL HandleNameConflict!
return make_error<ImportError>(ImportError::NameConflict);
}
There are open questions here:
D->getDeclName
or rather the name of the imported ClassTemplateDecl
or should we import the name here (again)? HandleNameConflict
?I think handleNameConflict
should not be called in this case. This is an ODR conflict but the problem is not correctable with a simple rename (or the template must be renamed somehow). It can be possible to use the ODR handling strategy 'liberal' if the list of template specializations (or other things in the AST) allows it that for the same parameter set multiple specializations are added.
Okay, that is a good point. I don't think we could add multiple specializations for the same template arguments. This means neither the renaming nor the "liberal" strategy could work. So in this case only our "conservative" strategy can work, but that is how it is already implemented.
There are cases (
FieldDecl
) when we don't callHandleNameConflict
but we should.