<table border="1" cellspacing="0" cellpadding="8">
<tr>
<th>Issue</th>
<td>
<a href=https://github.com/llvm/llvm-project/issues/75599>75599</a>
</td>
</tr>
<tr>
<th>Summary</th>
<td>
libclang python bindings give different result for template overloading
</td>
</tr>
<tr>
<th>Labels</th>
<td>
new issue
</td>
</tr>
<tr>
<th>Assignees</th>
<td>
</td>
</tr>
<tr>
<th>Reporter</th>
<td>
wouter-heerwegh
</td>
</tr>
</table>
<pre>
I'm trying to parse some C++ code with the clang python bindings, but I seem to get some weird behaviour when a function template is overloaded in different ways.
For example:
```python
import clang.cindex
def walk(node, t):
print(f'{" "*t} name: {node.spelling or node.displayname}, type: {node.type.spelling}, kind {node.kind}' )
if(node.referenced):
print(f"{" "*t} Has a definition: {node.referenced.location.line}")
for c in node.get_children():
walk(c, t + 1)
s = """
#include "stdio.h"
template <class T>
void foo(T bar)
{
bar++;
}
int main(int argv, char** argc){
foo(10);
}
"""
index = clang.cindex.Index.create()
tu = index.parse('tmp.cpp', unsaved_files=[('tmp.cpp', s)])
print('Translation unit:', tu.spelling)
walk(tu.cursor, 0)
```
This returns
```
name: foo, type: void, kind CursorKind.CALL_EXPR
Has a definition: 5
name: foo, type: void (*)(int), kind CursorKind.UNEXPOSED_EXPR
Has a definition: 5
name: foo, type: void (int), kind CursorKind.DECL_REF_EXPR
Has a definition: 5
```
This is indeed what I would expect. However if the foo function is called `foo<int>(10)`, the result changes to
```
name: , type: void, kind CursorKind.UNEXPOSED_EXPR
name: , type: <overloaded function type>, kind CursorKind.DECL_REF_EXPR
Has a definition: 11
name: foo, type: , kind CursorKind.OVERLOADED_DECL_REF
Has a definition: 11
```
Is there a big difference between overloading the function with a template argument vs not?
</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyUVl-P2ygQ_zTkZVTLwck6echDNn_U1a2uVW_v1LcVhrHNFYMFOO5--xPY6yTbdNuLLGLD8JuZ38wwMOdkpRE3ZHlPlvsZ63xt7KY3nUf7oUa0PVb1rDDiZ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