Skip to content

[libclang] Visit function template instantiations#67928

Open
Danacus wants to merge 2 commits intollvm:mainfrom
Danacus:template-functions-3
Open

[libclang] Visit function template instantiations#67928
Danacus wants to merge 2 commits intollvm:mainfrom
Danacus:template-functions-3

Conversation

@Danacus
Copy link
Copy Markdown

@Danacus Danacus commented Oct 1, 2023

This PR changes CursorVisitor::VisitFunctionTemplateDecl such that instantiations of the function template (e.g. template void foo<int>();) are visited as children of the FunctionTemplateDecl. This also applies to class methods.

The use case for this I have in mind would be to add limited support for function templates in rust-bindgen (see rust-lang/rust-bindgen#2650).

Additionally, I have taken the liberty to add CXCursor_CXXMethod to the list of cursors supported by getTemplateArgument, since I found it a bit odd that this was not the case before.

Please let me know if there is anything that needs to be changed, I'm happy to make changes if necessary.

@llvmbot llvmbot added the clang Clang issues not falling into any other category label Oct 1, 2023
@github-actions
Copy link
Copy Markdown

github-actions Bot commented Oct 1, 2023

✅ With the latest revision this PR passed the C/C++ code formatter.

@Danacus Danacus force-pushed the template-functions-3 branch from a0f10a6 to d57843b Compare October 7, 2023 08:35
@Danacus Danacus force-pushed the template-functions-3 branch from d57843b to 6e43193 Compare October 7, 2023 08:44
@AaronBallman AaronBallman self-requested a review October 7, 2023 12:46
@AaronBallman AaronBallman added the clang:as-a-library libclang and C++ API label Oct 7, 2023
Copy link
Copy Markdown
Contributor

@Endilll Endilll left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

CC @AaronBallman I guess this has fallen through the cracks after you added yourself as a reviewer.

if (VisitAttributes(FD) || VisitFunctionDecl(FD))
return true;

for (auto *Child : D->specializations())
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure if adding this to the existing API is a good idea

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Agreed, I think visiting the specializations would come as a surprise to consumers of the API. We already have VisitClassTemplateSpecializationDecl (and similar for partial specializations), so I would expect this is already being visited anyway, right?

@AaronBallman
Copy link
Copy Markdown
Contributor

CC @AaronBallman I guess this has fallen through the cracks after you added yourself as a reviewer.

It sure did, sorry about that @Danacus!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

clang:as-a-library libclang and C++ API clang Clang issues not falling into any other category

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants