c++: clang-tidy complains it can’t find common headers (especially under conda/conda-forge)


clang-tidy might complain it can’t find headers that it should be able to find as a matter of course:

c/driver/postgresql/connection.h:20:10: error: 'cstdint' file not found [clang-diagnostic-error]
#include <cstdint>
         ^~~~~~~~~

It turns out that clang-tidy needs to be able to resolve where the compiler looks for these standard headers, and if the compiler used is a symlink, it won’t find them. Details are in llvm/llvm-project#46804.

To fix it, use a compile_commands.json (e.g. for CMake, set CMAKE_EXPORT_COMPILE_COMMANDS=ON) and make sure that CC and CXX point to the actual compilers, not a symlink:

export CC=$(readlink -f ${CC:-$(which cc)})
export CXX=$(readlink -f ${CXX:-$(which cxx)})

cmake ...