Clang-Tidy fails to analyze QT project that uses Pybind11 due to reserved 'slots' keyword
-
I would like to use Clang-Tidy to lint my Cmake QT project, which I develop in QTCreator. It is a C++ project that uses Pybind11 to interface with Python code.
Unfortunately, running Clang-tidy from within QTCreator on this project always fails with the following error:
C:\msys64\ucrt64\include\python3.12/object.h:352:23: error: expected member name or ';' after declaration specifiers [clang-diagnostic-error] 352 | PyType_Slot *slots; /* terminated by slot==0. */ | ~~~~~~~~~~~ ^ 08:56:12: Error: Failed to analyze 1 files.
Online information about this error seems sparse. But what I have dug up seems to suggest it is Python's object.h uses a reserved keyword in the form of
PyType_Slot *slots;
There is a single post suggesting that defining
PYBIND11_NO_KEYWORDS
can help - but I suspect this is a myth as I cannot find more than one reference to it anywhere, and searching for the keyword doesn't turn up anything in the python install directory.How can I get clang-tidy working in QTCreator?
-
It looks like consistently moving the include of Pybind11 headers before QT Headers has fixed it.
However, this also goes for the full include tree. So if A includes B, and B includes Pybind, A should include B before including any QT Headers (QObject, QProcess, QVector, etc)