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

    <tr>
        <th>Summary</th>
        <td>
            CXError_ASTReadError using libclang on LLVM 15.x due to possibly incorrect ODR violations 
        </td>
    </tr>

    <tr>
      <th>Labels</th>
      <td>
            c++20,
            libclang
      </td>
    </tr>

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

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

<pre>
    We recently met a bug in QDoc (https://bugreports.qt.io/browse/QTBUG-94365 [this is a reopened old bug, so only the recent comments are relevant]) where we encountered a series of `CXError_ASTReadError` during the normal processing of our documentation.

QDoc currently uses libclang to parse C++ files to extract and verify our documentation.

On Clang 15.x releases, we started noticing a series of `CXError_ASTReadError` when parsing many of the source files in the Qt codebase.

Those errors do not seem to appear on Clang 12/13/14.x and neither on the current development branch.
Furthermore, the issue appears to be platform-independent.

The `CXError_ASTReadError` seems to be generated as a result of libclang incurring in ODR violations in [qtbase/src/corelib/tools/qhashfunction.h](https://github.com/qt/qtbase/blob/ca254a0937d58e573a0e2b210590de2a02326e5f/src/corelib/tools/qhashfunctions.h), for example:

`"'qHash' has different definitions in different modules; defined here first difference is 1st parameter with name"`

QDoc generates a single PCH, trough `clang_saveTranslationUnit`, for all of headers of the module it is parsing, later including it trough `--include-pch` when parsing a source file.
Compiling without including the PCH seems to avoid the issue.

Similarly, QDoc compiles with the C++20 standard. When a C++17 standard is enforced, the issue is not encountered.

Bisecting seems to show that the issue originated between 14.x and 15.x at https://reviews.llvm.org/D120812 and is later generally present in 15.x, albeit disappearing on certain heads.
For example, it is not present at 3e7350f3173b02b3c77917100b2228f1964c55c6 / https://reviews.llvm.org/D128695.

We unfortunately were not able to produce a minimum project to replicate the issue.

We couldn't directly pinpoint to what is generating the error, nor are we entirely sure that this does not stem from some errors on our side.
We supposed this might be a bug as this only currently happens on Clang 15.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