<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/76037>76037</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
[Question] Get the number of template parameters of a un-speciliazed function template declaration
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
isVoid
</td>
</tr>
</table>
<pre>
Hello LLVM community. Please point me to a different direction if this is not the right place for submitting a help request.
Recently I'm experimenting AST parsing with the clang-C API. Everything worked well so far until I'm starting to process template function arguments, the usual `clang_Cursor_getNumTemplateArguments` doesn't seem to perform what it's expected to do. Here's a min repro:
```c++
//template.hpp
template<typename T, int i, template<typename> class C>
void foo(T t, C<T> c) {
c.push_back(i);
}
```
```c++
#include <clang-c/Index.h>
#include <iostream>
#include <string>
int main()
{
// Create translation unit
CXIndex index = clang_createIndex(0, 1);
CXTranslationUnit unit = clang_createTranslationUnitFromSourceFile(
index,
"template.hpp",
0,
nullptr,
0,
nullptr);
// Get cursor
CXCursor cursor = clang_getTranslationUnitCursor(unit);
// Traverse
clang_visitChildren(
cursor,
[](CXCursor c, CXCursor parent, CXClientData client_data) {
CXCursorKind kind = clang_getCursorKind(c);
CXString name = clang_getCursorSpelling(c);
if (std::string(clang_getCString(name)) == "foo")
{
int num_params = clang_Cursor_getNumArguments(c);
int num_template_params = clang_Cursor_getNumTemplateArguments(c);
printf("%s %s %dargs %dtempargs\n",
clang_getCString(name),
clang_getCString(clang_getCursorKindSpelling(kind)),
num_params,
num_template_params
);
clang_disposeString(name);
return CXChildVisit_Break;
}
return CXChildVisit_Recurse;
},
nullptr);
}
```
What I expected to print:
```
foo FunctionTemplate 2args 3tempargs
```
Why I think this way: 2 args are the function parameters (`t` and `c`). 3 tempargs are the 3 template parameters `T, i, C`.
What I got:
```
foo FunctionTemplate -1args -1tempargs
```
Would appreciate any reply!
</pre>
<img width="1px" height="1px" alt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