[clang] [clang] fix RecursiveASTVisitor traversal from type to decl (PR #132551)
via cfe-commits
cfe-commits at lists.llvm.org
Sat Mar 22 07:33:56 PDT 2025
llvmbot wrote:
<!--LLVM PR SUMMARY COMMENT-->
@llvm/pr-subscribers-clang
Author: Matheus Izvekov (mizvekov)
<details>
<summary>Changes</summary>
For that visitor, it is not expected that a type can traverse into a declaration. This makes the MemberPointer visitor conform to that rule.
This turns the base class visitor into a CXXRecordType visitor, and only performs that visit in case it points to something different than the qualifier does.
Fixes a regression reported here: https://github.com/llvm/llvm-project/pull/132401#issuecomment-2745184537
As this fixes a regression which has not been released, there are no release notes.
---
Full diff: https://github.com/llvm/llvm-project/pull/132551.diff
2 Files Affected:
- (modified) clang/include/clang/AST/RecursiveASTVisitor.h (+3-1)
- (modified) clang/test/SemaCXX/member-pointer.cpp (+11)
``````````diff
diff --git a/clang/include/clang/AST/RecursiveASTVisitor.h b/clang/include/clang/AST/RecursiveASTVisitor.h
index e93d1d8eab56f..0d5d515c0e6f7 100644
--- a/clang/include/clang/AST/RecursiveASTVisitor.h
+++ b/clang/include/clang/AST/RecursiveASTVisitor.h
@@ -1005,7 +1005,9 @@ DEF_TRAVERSE_TYPE(RValueReferenceType,
DEF_TRAVERSE_TYPE(MemberPointerType, {
TRY_TO(TraverseNestedNameSpecifier(T->getQualifier()));
- TRY_TO(TraverseDecl(T->getMostRecentCXXRecordDecl()));
+ if (T->isSugared())
+ TRY_TO(TraverseType(
+ QualType(T->getMostRecentCXXRecordDecl()->getTypeForDecl(), 0)));
TRY_TO(TraverseType(T->getPointeeType()));
})
diff --git a/clang/test/SemaCXX/member-pointer.cpp b/clang/test/SemaCXX/member-pointer.cpp
index b6ab7d38610c8..3d9dd05755b8c 100644
--- a/clang/test/SemaCXX/member-pointer.cpp
+++ b/clang/test/SemaCXX/member-pointer.cpp
@@ -344,3 +344,14 @@ namespace GH132494 {
};
template struct A<E>; // expected-note {{requested here}}
} // namespace GH132494
+
+namespace GH132401 {
+ template <typename Func> struct CallableHelper {
+ static auto Resolve() -> Func;
+ };
+ struct QIODevice {
+ void d_func() { (void)d_ptr; }
+ int d_ptr;
+ };
+ template struct CallableHelper<void (QIODevice::*)()>;
+} // namespace GH132401
``````````
</details>
https://github.com/llvm/llvm-project/pull/132551
More information about the cfe-commits
mailing list