We fail to import a ClassTemplateDecl if the "To" context already contains a definition and then a forward decl.
This is because localUncachedLookup does not find the definition.
This is not a lookup error, the parser behaves differently than assumed in the importer code.
A DeclContext contains one DenseMap (LookupPtr) which maps names to lists.
The list is a special list StoredDeclsList which is optimized to have one element.
During building the initial AST, the parser first adds the definition to the DeclContext.
Then during parsing the second declaration (the forward decl) the parser again calls DeclContext::addDecl but that will not add a new element to the StoredDeclsList rarther it simply overwrites the old element with the most recent one.
This patch fixes the error by finding the definition in the redecl chain.
Added tests for the same issue with CXXRecordDecl and with ClassTemplateSpecializationDecl.
These tests pass and they pass because in VisitRecordDecl and in VisitClassTemplateSpecializationDecl we already use D->getDefinition() after the lookup.
Details
Details
Diff Detail
Diff Detail
- Repository
- rC Clang
Event Timeline
Comment Actions
Hello Gabor,
The patch is fine, I have found only some style issues.
lib/AST/ASTImporter.cpp | ||
---|---|---|
4073 | forward | |
4121–4127 | is a definition? | |
4124 | let's; if it is available | |
4126 |
| |
unittests/AST/ASTImporterTest.cpp | ||
1550 | Although long names make me happy, this one exceeds 80-char limit. We can abbreviate "Specialization" to "Spec". | |
unittests/AST/DeclMatcher.h | ||
52 | Predicate, Count (member names should start with capital). |
Comment Actions
@a.sidorin
Yes, that is a very good idea.
Just created a new patch which adds that switch for the tests which use the TestBase.
https://reviews.llvm.org/D47367
forward