]> granicus.if.org Git - clang/commit
Fix duplicate class template definitions problem
authorGabor Marton <martongabesz@gmail.com>
Wed, 23 May 2018 13:53:36 +0000 (13:53 +0000)
committerGabor Marton <martongabesz@gmail.com>
Wed, 23 May 2018 13:53:36 +0000 (13:53 +0000)
commitf7ac5a44796bbb164c285e2c914f3261e7a1ecef
tree2c8dc591926171c8cab17869fd326688d99fd334
parente886a72013328af17389ea67633d6673adee1985
Fix duplicate class template definitions problem

Summary:
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.

Reviewers: a.sidorin, xazax.hun, szepet

Subscribers: rnkovacs, dkrupp, cfe-commits

Differential Revision: https://reviews.llvm.org/D46950

git-svn-id: https://llvm.org/svn/llvm-project/cfe/trunk@333082 91177308-0d34-0410-b5e6-96231b3b80d8
lib/AST/ASTImporter.cpp
unittests/AST/ASTImporterTest.cpp
unittests/AST/DeclMatcher.h