davrec added a comment.
In D131685#3716354 <https://reviews.llvm.org/D131685#3716354>, @balazske wrote:
> I really do not know why parent of the node for the owned `TagDecl` node is
> the `FriendDecl` and not a `TypeLoc` node, but it is working.
> The code `struct A { friend struct Fr; };` caused no problems either (no
> duplicate visit of `struct Fr`).
This is because the TraverseDecl(OwnedTagDecl) call is performed in the
TraverseFriendDecl call, after the TraverseTypeLoc call has already returned --
and I assume the ParentMap just looks uses the stack of traversal calls to
generate the parents.
That said, this does raise the question of whether we should instead be
changing DEF_TRAVERSE_TYPE(Elaborated) to *always* traverse its owned tag decl;
that way the parent would be the TypeLoc node. However in more usual cases an
ET's owned tag decl is added to the parent DeclContext; e.g. for `struct B {int
i} data;`, `B` and `data` are added as separate declarations in the parent
context (which is annoying -- so probably the Type node really *should* always
be the parent of that decl, if we were writing the AST from scratch! -- but it
is what it is). So if traversed all owned tag decls, we would get some
duplicate visitations.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D131685/new/
https://reviews.llvm.org/D131685
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits