Fix template-argument accessors for function and variable template specializations#721
Merged
tannergooding merged 1 commit intoJul 13, 2026
Conversation
…ecializations clangsharp_Cursor_getNumTemplateArguments returned a bool (TAL && TAL->size()) rather than the actual count for a FunctionDecl template specialization, so any specialization with more than one argument wrongly reported 1. Return the real size, matching the sibling branches. clangsharp_Cursor_getTemplateArgument only handled the derived VarTemplatePartialSpecializationDecl, whereas getNumTemplateArguments handles the base VarTemplateSpecializationDecl. A full (non-partial) variable template specialization therefore reported N arguments but returned a null CX_TemplateArgument for each. Handle the base class, which subsumes the partial case. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes two correctness bugs in the native libClangSharp shim, both in the template-argument accessors and both the same class of bug.
clangsharp_Cursor_getNumTemplateArgumentsreturnedTAL && TAL->size()for aFunctionDecltemplate specialization -- i.e. abool(0/1), not the count. So a specialization with more than one template argument wrongly reported1. Every sibling in the function returns the real.size(); this now does too via a guard-then-size (TAL ? TAL->size() : 0), matching the guard in the siblinggetTemplateArgument.clangsharp_Cursor_getTemplateArgumentonly handled the derivedVarTemplatePartialSpecializationDecl, where-as the siblinggetNumTemplateArgumentshandles the baseVarTemplateSpecializationDecl. For a full (non-partial) variable template specialization,getNumreturnedNbutgetTemplateArgument(i)returned a nullCX_TemplateArgumentfor everyi. Handling the base subsumes the partial case (partial derives from it), so partial behavior is unchanged and full specializations now return real arguments.Adds regression tests in
ClangSharp.UnitTests(FunctionTemplateSpecializationArgsTest,VarTemplateSpecializationArgsTest) covering a function-template specialization with >1 argument and a full variable-template specialization. Confirmed both fail against the current prebuilt native package exactly as the bugs predict (count1vs2; argsIsNullfor the var spec) and are structurally correct.The tests are gated behind a runtime libClang-version check that
Assert.Ignores while the pinned21.1prebuilt native package is in use, since that package predates this native fix. Rebuilding the native lib off21.1auto-unskips them.