[PATCH] D46950: Fix duplicate class template definitions problem

Gabor Marton via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Wed May 16 08:23:29 PDT 2018


martong created this revision.
martong added reviewers: a.sidorin, xazax.hun, szepet.
Herald added subscribers: cfe-commits, dkrupp, rnkovacs.

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.


Repository:
  rC Clang

https://reviews.llvm.org/D46950

Files:
  lib/AST/ASTImporter.cpp
  unittests/AST/ASTImporterTest.cpp
  unittests/AST/DeclMatcher.h

-------------- next part --------------
A non-text attachment was scrubbed...
Name: D46950.147098.patch
Type: text/x-patch
Size: 9618 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20180516/3db4379e/attachment.bin>


More information about the cfe-commits mailing list