[PATCH] D131685: [clang][AST] RecursiveASTVisitor should visit owned TagDecl of friend type.

David Rector via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Aug 16 08:13:45 PDT 2022


davrec added a comment.

Once the FIXME is removed this looks good, but I was involved in this so better if @sammccall can give the thumbs up at least to the RecursiveASTVisitor code.



================
Comment at: clang/include/clang/AST/RecursiveASTVisitor.h:1577-1578
 DEF_TRAVERSE_DECL(FriendTemplateDecl, {
+  // FIXME: Traverse getOwnedTagDecl like at the FriendDecl case?
+  // (FriendTemplateDecl is not used)
   if (D->getFriendType())
----------------
I don't think anything is necessary here, because we should never see an `OwnedTagDecl` here.
In the FriendDecl case the ElaboratedType only has an OwnedTagDecl when `struct Fr` has not yet been declared before the friend decl.
In the documentation of FriendTemplateDecl on the other hand these examples are given:
```
/// template \<typename T> class A {
///   friend class MyVector<T>; // not a friend template
///   template \<typename U> friend class B; // not a friend template
///   template \<typename U> friend class Foo<T>::Nested; // friend template
/// };
```
So, a FriendTemplateDecl is only created when referencing a nested class template member.  But that *must* have been declared before the friend decl, or we will get an error:

```
template<typename T> struct B;
template<typename T> struct A { template<typename U> friend struct B<T>::Fr; }; //ERROR: no member named 'Fr' in B<T>
```

So the OwnedTagDecl should always be nullptr here/the issue should never arise in this case.



Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D131685/new/

https://reviews.llvm.org/D131685



More information about the cfe-commits mailing list