[AST] include decls owned by FriendDecl in -ast-dump
authorSam McCall <sam.mccall@gmail.com>
Tue, 10 Jan 2023 09:51:34 +0000 (10:51 +0100)
committerSam McCall <sam.mccall@gmail.com>
Tue, 10 Jan 2023 12:59:58 +0000 (13:59 +0100)
Differential Revision: https://reviews.llvm.org/D141362

clang/include/clang/AST/ASTNodeTraverser.h
clang/test/AST/ast-dump-decl.cpp

index 151a9c6..3089658 100644 (file)
@@ -644,8 +644,15 @@ public:
   }
 
   void VisitFriendDecl(const FriendDecl *D) {
-    if (!D->getFriendType())
+    if (D->getFriendType()) {
+      // Traverse any CXXRecordDecl owned by this type, since
+      // it will not be in the parent context:
+      if (auto *ET = D->getFriendType()->getType()->getAs<ElaboratedType>())
+        if (auto *TD = ET->getOwnedTagDecl())
+          Visit(TD);
+    } else {
       Visit(D->getFriendDecl());
+    }
   }
 
   void VisitObjCMethodDecl(const ObjCMethodDecl *D) {
index 61e7d9e..e22ea60 100644 (file)
@@ -784,6 +784,7 @@ template<typename T> class TestFriendDecl {
 // CHECK-NEXT:   FriendDecl
 // CHECK-NEXT:     FunctionDecl{{.*}} foo
 // CHECK-NEXT:   FriendDecl{{.*}} 'class A':'A'
+// CHECK-NEXT:     CXXRecordDecl{{.*}} class A
 // CHECK-NEXT:   FriendDecl{{.*}} 'T'
 
 namespace TestFileScopeAsmDecl {