Skip to content

Conversation

@egorzhdan
Copy link
Contributor

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.

…e 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`.
@llvmbot llvmbot added clang Clang issues not falling into any other category clang:frontend Language frontend issues, e.g. anything involving "Sema" labels Nov 7, 2024
@llvmbot
Copy link
Member

llvmbot commented Nov 7, 2024

@llvm/pr-subscribers-clang

Author: Egor Zhdan (egorzhdan)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/115336.diff

1 Files Affected:

  • (modified) clang/include/clang/AST/TemplateArgumentVisitor.h (+2-1)
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);

@egorzhdan egorzhdan changed the title [clang] Dispatch default overloads of TemplateArgumentVisitor to the implementation [Clang] Dispatch default overloads of TemplateArgumentVisitor to the implementation Nov 7, 2024
@egorzhdan egorzhdan merged commit d4525b0 into main Nov 7, 2024
11 checks passed
@egorzhdan egorzhdan deleted the users/egorzhdan/template-arg-visitor branch November 7, 2024 23:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:frontend Language frontend issues, e.g. anything involving "Sema" clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants