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

    <tr>
        <th>Summary</th>
        <td>
            How to get error message from Python/clang.cindex C++ parser
        </td>
    </tr>

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

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

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

<pre>
    The following Python code is supposed to parse C++ code:
``
import clang.cindex

index = clang.cindex.Index.create()
translation_unit = index.parse(cpp_source_filename, args=['-std=c++20'])
```

Problems start if function parse raises a `TranslationUnitLoadError`. If I catch and print the `TranslationUnitLoadError` instance, I only get "Error parsing translation unit."

How to get a decent compiler error message, or at least the location of the error in the source file?

Web search yields the advise to look into `translation_unit.diagnostics` - but this is not pertinent here because the error is raised before `translation_unit` is set.

</pre>
<img width="1px" height="1px" alt="" src="http://email.email.llvm.org/o/eJyEU8GOpDYQ_RpzKQ2iDQ3dBw4722llpBz2sFGOI2MX4F1jI1exk_77yKaz0xNFWgkZjF9VvXrPpYjs5BF7cXwWx0uhNp5D7L-9bczfsRiCufVfZ4QxOBferJ_gy43n4EEHg2AJaFvXQGiAA6wqEsJnIZ-FfM4IUX8S1UVUn0RbpSd_22UNkUE75adSW2_w7ztoP04_QNSXD4jyJa86omIU8iTkeYdzVJ6cYhv86-Yt58g9JPMR8qTX9ZXCFjW-jtahVwsK-RlUnEjUl9S57J6IjagveicvKyE7cbz8rHLn_28L-_olhsHhQkCsIoMdYdy8TkzuUkRlCQkUiLb6-s7zT2_5j6DMbzGGKNqqhJcRXkAr1jMob2CN1jPwjL8IBOuJlde5nRcI3t1gQgYhZYZkGsm0B5EgiVQKKR87-T28JQNTrAKDGj2DDstqHUbAnGpBIjXlSiGCYnCoaCfpgt5ThzHv9wDr82YXHpLwor4-Fv0LByBUUc9ws-gMZbwyPyxhYuNC-A7Wc0gq_Nfm0lg1-UBsNSUlnmDYEhtL6Vb6wLBiZOtTJzNGhAG12lLid4K0G2RgwDFE_L8yWWQCQi530oXpa3Ouz6rA_tBVh6o6yuOpmPvubDqsW92Mo6rUYNq2kU07SD2catTNubC9rGR9OMj2UMuuPpVVp2TXmlqP47k760o0FS7KutK5H0sZ4lRYog37rm6aU-HUgI7ynEqZJyN5eLwUsU_4p2GbSDSVs8T0noEtO-wf7P1gJowxLPeJFvL6OG8_xzjf5Fhs0fUz80pppOVVyOtked6GUodFyGsqeH89rTF8Q81CXjN_EvKaW_gnAAD__1AEdE8">