================
@@ -1438,29 +1438,40 @@ CXCursor clang_Cursor_getArgument(CXCursor C, unsigned
i) {
int clang_Cursor_getNumTemplateArguments(CXCursor C) {
CXCursorKind kind = clang_getCursorKind(C);
- if (kind != CXCursor_FunctionDecl && kind != CXCursor_StructDecl &&
- kind != CXCursor_ClassDecl &&
+ if (kind != CXCursor_FunctionDecl && kind != CXCursor_CXXMethod &&
+ kind != CXCursor_StructDecl && kind != CXCursor_ClassDecl &&
kind != CXCursor_ClassTemplatePartialSpecialization) {
return -1;
}
- if (const auto *FD =
- llvm::dyn_cast_if_present<clang::FunctionDecl>(getCursorDecl(C))) {
+ const TemplateArgumentList *TAL = nullptr;
+
+ if (const auto *FD = dyn_cast_if_present<FunctionDecl>(getCursorDecl(C))) {
const FunctionTemplateSpecializationInfo *SpecInfo =
FD->getTemplateSpecializationInfo();
if (!SpecInfo) {
return -1;
}
- return SpecInfo->TemplateArguments->size();
+ TAL = SpecInfo->TemplateArguments;
}
- if (const auto *SD =
- llvm::dyn_cast_if_present<clang::ClassTemplateSpecializationDecl>(
- getCursorDecl(C))) {
- return SD->getTemplateArgs().size();
+ if (!TAL) {
+ if (const auto *SD = dyn_cast_if_present<ClassTemplateSpecializationDecl>(
+ getCursorDecl(C))) {
+ TAL = &SD->getTemplateArgs();
+ }
}
- return -1;
+ if (!TAL)
+ return -1;
+
+ unsigned ArgCount = TAL->size();
+ for (unsigned i = 0; i < TAL->size(); i++) {
+ const TemplateArgument &Arg = TAL->get(i);
+ if (Arg.getKind() == TemplateArgument::Pack)
+ ArgCount += Arg.pack_size() - 1;
----------------
Endilll wrote:
I'm not sure we can do this in the existing function given our API and ABI
stability promises.
CC @AaronBallman
https://github.com/llvm/llvm-project/pull/183504
_______________________________________________
cfe-commits mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits