[clang] 98ae361 - [AST] include decls owned by FriendDecl in -ast-dump
Sam McCall via cfe-commits
cfe-commits at lists.llvm.org
Tue Jan 10 05:00:10 PST 2023
Author: Sam McCall
Date: 2023-01-10T13:59:58+01:00
New Revision: 98ae3616cd1536643a78beeddff119c028f71df6
URL: https://github.com/llvm/llvm-project/commit/98ae3616cd1536643a78beeddff119c028f71df6
DIFF: https://github.com/llvm/llvm-project/commit/98ae3616cd1536643a78beeddff119c028f71df6.diff
LOG: [AST] include decls owned by FriendDecl in -ast-dump
Differential Revision: https://reviews.llvm.org/D141362
Added:
Modified:
clang/include/clang/AST/ASTNodeTraverser.h
clang/test/AST/ast-dump-decl.cpp
Removed:
################################################################################
diff --git a/clang/include/clang/AST/ASTNodeTraverser.h b/clang/include/clang/AST/ASTNodeTraverser.h
index 151a9c6b58524..3089658305bfc 100644
--- a/clang/include/clang/AST/ASTNodeTraverser.h
+++ b/clang/include/clang/AST/ASTNodeTraverser.h
@@ -644,8 +644,15 @@ class ASTNodeTraverser
}
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) {
diff --git a/clang/test/AST/ast-dump-decl.cpp b/clang/test/AST/ast-dump-decl.cpp
index 61e7d9ec60d09..e22ea60b26061 100644
--- a/clang/test/AST/ast-dump-decl.cpp
+++ b/clang/test/AST/ast-dump-decl.cpp
@@ -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 {
More information about the cfe-commits
mailing list