Issue 75599
Summary libclang python bindings give different result for template overloading
Labels new issue
Assignees
Reporter wouter-heerwegh
    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?
_______________________________________________
llvm-bugs mailing list
[email protected]
https://lists.llvm.org/cgi-bin/mailman/listinfo/llvm-bugs

Reply via email to