Page MenuHomePhabricator

Allow getting template args for ClassTemplateSpecializations

Authored by anderslanglands on Sep 22 2022, 1:01 AM.



Modifies clang_Cursor_getNumTemplateArguments() and friends to work on Struct, Class and ClassTemplatePartialSpecialization decls as well as functions

Diff Detail

Event Timeline

Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 1:01 AM
anderslanglands requested review of this revision.Sep 22 2022, 1:01 AM
Herald added a project: Restricted Project. · View Herald TranscriptSep 22 2022, 1:01 AM
Herald added a subscriber: cfe-commits. · View Herald Transcript

Hello again, this generalizes the template argument functionality to operate on cursor kinds other than functions.

I could use some help creating a test for this. On my previous patch I was able to just copy/paste and modify an existing test, but from a quick scan of the current tests I can't see how I'd modify one of them to test this functionality.

Updating doc comments to reflect new functionality

Mostly nits from me (FWIW, we use auto when the type is explicitly spelled out in the initialization and we don't usually use else after an unconditional return as a matter of coding style.) In terms of the test coverage, I would probably make a new test modeled after


Since we're in the area already...


CXCursor_StructDecl is interesting -- does that only get used in C or will it also show up in C++? If it's C-only, we can drop that bit.


Same question here about struct decl as above.

anderslanglands marked 7 inline comments as done.

Add testing, address style notes

I ended up modifying c-index-test to print out the template arguments in the same way it does for FunctionDecl, which ends up working all cases in the existing test suite. The only other thing I added was a specific case in index-templates.cpp to check whether it catches StructDecl too (it does).


It does. I added a case to index-templates.cpp that tests for this.

aaron.ballman accepted this revision.Sep 23 2022, 6:54 AM

LGTM! I can fix up the minor nit with the release note formatting when I land on your behalf.

This revision is now accepted and ready to land.Sep 23 2022, 6:54 AM