<table border="1" cellspacing="0" cellpadding="8">
    <tr>
        <th>Issue</th>
        <td>
            <a href=https://github.com/llvm/llvm-project/issues/162210>162210</a>
        </td>
    </tr>

    <tr>
        <th>Summary</th>
        <td>
            Python clang package recognizes std::string_view as int
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            clang
      </td>
    </tr>

    <tr>
      <th>Assignees</th>
      <td>
      </td>
    </tr>

    <tr>
      <th>Reporter</th>
      <td>
          OppositeNor
      </td>
    </tr>
</table>

<pre>
    The pip package [clang](https://pypi.org/project/clang/) recognizes the C++ standard library type `std::string_view` as `int`.

```cpp
#include <string_view>

std::string_view str_view_global;

struct TestStruct {
    std::string_view str_view;
};
```

```python
import clang.cindex

index = clang.cindex.Index.create()
tu = index.parse(
    "test.cpp",
    options=clang.cindex.TranslationUnit.PARSE_DETAILED_PROCESSING_RECORD
)

if tu is None or tu.cursor is None:
    raise RuntimeError("Failed to parse C++ file.")


for cursor in tu.cursor.get_children():
    if cursor.spelling == "str_view_global":
        print(cursor.type.spelling, cursor.spelling)
    if cursor.kind == clang.cindex.CursorKind.STRUCT_DECL and cursor.spelling == "TestStruct":
        for field in cursor.get_children():
            if field.kind != clang.cindex.CursorKind.FIELD_DECL:
                continue
            print(field.type.spelling, field.spelling)
```

Output:

```
❯ python ./test.py
int str_view_global
int str_view
```

Version info:

```
❯ pip show clang
Name: clang
Version: 20.1.5
Summary: libclang python bindings
Home-page: http://clang.llvm.org/
Author: LLVM team - pypi upload by Loic Jaquemet
Author-email: 
License: Apache-2.0 with LLVM exception
Location: /home/oppositenormal/miniforge3/envs/white-bird-engine/lib/python3.12/site-packages
Requires: 
Required-by: 
```
</pre>
<img width="1" height="1" alt="" src="http://email.email.llvm.org/o/eJyMVVFzozYQ_jXyi8YMFgHCAw_ENm1aN7lxcvfqEbCG7QmJk0Ry7q_vSGDnnNxcy3gSod399uPTapcbg60EyEl8R-LNgo-2Uzp_HAZl0MKD0otKNaf8uQM64EAHXn_lLVAS39WCy5b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