[clang] [clang][ASTImporter] Fix import of variable template redeclarations. (PR #72841)
Balázs Kéri via cfe-commits
cfe-commits at lists.llvm.org
Fri Jan 12 09:01:17 PST 2024
================
@@ -6245,17 +6245,21 @@ ExpectedDecl ASTNodeImporter::VisitVarTemplateDecl(VarTemplateDecl *D) {
D->getTemplatedDecl()))
continue;
if (IsStructuralMatch(D, FoundTemplate)) {
- // The Decl in the "From" context has a definition, but in the
- // "To" context we already have a definition.
+ // FIXME Check for ODR error if the two definitions have
+ // different initializers?
VarTemplateDecl *FoundDef = getTemplateDefinition(FoundTemplate);
- if (D->isThisDeclarationADefinition() && FoundDef)
- // FIXME Check for ODR error if the two definitions have
- // different initializers?
- return Importer.MapImported(D, FoundDef);
- if (FoundTemplate->getDeclContext()->isRecord() &&
- D->getDeclContext()->isRecord())
- return Importer.MapImported(D, FoundTemplate);
-
+ if (D->getDeclContext()->isRecord()) {
+ assert(FoundTemplate->getDeclContext()->isRecord() &&
+ "Member variable template imported as non-member, "
+ "inconsistent imported AST?");
----------------
balazske wrote:
The existing "To" AST can be somehow invalid or declarations can be in wrong scope, because previous wrong AST imports and structural equivalence problems, or here a wrong declaration may be found. This assertion looks to check for such problems (check `FoundTemplate->getDeclContext()->isRecord()` if `D->getDeclContext()->isRecord()`).
https://github.com/llvm/llvm-project/pull/72841
More information about the cfe-commits
mailing list