[clang] [clang] Dispatch default overloads of `TemplateArgumentVisitor` to the implementation (PR #115336)

Egor Zhdan via cfe-commits cfe-commits at lists.llvm.org
Thu Nov 7 08:19:55 PST 2024


https://github.com/egorzhdan created https://github.com/llvm/llvm-project/pull/115336

This fixes an issue where overriding `clang::ConstTemplateArgumentVisitor::VisitTemplateArgument` in an implementation visitor class did not have the desired effect: the overload was not invoked when one of the visitor methods (e.g. `VisitDeclarationArgument`) is not implemented, instead it dispatched to `clang::ConstTemplateArgumentVisitor::VisitTemplateArgument` itself and always returned a default-initialized result.

This makes `TemplateArgumentVisitor` and `ConstTemplateArgumentVisitor` follow the implicit convention that is followed elsewhere in Clang AST, in `RecursiveASTVisitor` and `TypeVisitor`.

>From 3d02ef56963fb5842b3484e7006fb87fa5d9aa6f Mon Sep 17 00:00:00 2001
From: Egor Zhdan <e_zhdan at apple.com>
Date: Thu, 7 Nov 2024 16:16:45 +0000
Subject: [PATCH] [clang] Dispatch default overloads of
 `TemplateArgumentVisitor` to the implementation

This fixes an issue where overriding `clang::ConstTemplateArgumentVisitor::VisitTemplateArgument` in an implementation visitor class did not have the desired effect: the overload was not invoked when one of the visitor methods (e.g. `VisitDeclarationArgument`) is not implemented, instead it dispatched to `clang::ConstTemplateArgumentVisitor::VisitTemplateArgument` itself and always returned a default-initialized result.

This makes `TemplateArgumentVisitor` and `ConstTemplateArgumentVisitor` follow the implicit convention that is followed elsewhere in Clang AST, in `RecursiveASTVisitor` and `TypeVisitor`.
---
 clang/include/clang/AST/TemplateArgumentVisitor.h | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/clang/include/clang/AST/TemplateArgumentVisitor.h b/clang/include/clang/AST/TemplateArgumentVisitor.h
index cf0d3220158063..923f045a995703 100644
--- a/clang/include/clang/AST/TemplateArgumentVisitor.h
+++ b/clang/include/clang/AST/TemplateArgumentVisitor.h
@@ -52,7 +52,8 @@ class Base {
 #define VISIT_METHOD(CATEGORY)                                                 \
   RetTy Visit##CATEGORY##TemplateArgument(REF(TemplateArgument) TA,            \
                                           ParamTys... P) {                     \
-    return VisitTemplateArgument(TA, std::forward<ParamTys>(P)...);            \
+    return static_cast<ImplClass *>(this)->VisitTemplateArgument(              \
+        TA, std::forward<ParamTys>(P)...);                                     \
   }
 
   VISIT_METHOD(Null);



More information about the cfe-commits mailing list