LLVM on MacOs - unknown type name 'template' in standard file iosfwd

Viewed 512

I installed LLVM on MacOS 10.13 using homebrew:

brew install --with-toolchain llvm

Then I exported required variables, based on this guide.

export PATH="/usr/local/opt/llvm/bin:$PATH"
export CC=/usr/local/opt/llvm/bin/clang
export CXX=/usr/local/opt/llvm/bin/clang++
export LLVM_OPTIONS="-L/usr/local/opt/llvm/lib -Wl,-rpath,/usr/local/opt/llvm/lib "\
"-I/usr/local/opt/llvm/include -I/usr/local/opt/llvm/include/c++/v1/"

When running clang-tidy:

clang-tidy myheaderlib.h -- $LLVM_OPTIONS

I get errors, all of them are related to standard files:

/usr/local/opt/llvm/include/c++/v1/iosfwd:96:1: error: unknown type name '_LIBCPP_BEGIN_NAMESPACE_STD'
/usr/local/opt/llvm/include/c++/v1/iosfwd:100:1: error: unknown type name 'template'
...

What may be the cause?

1 Answers

As I discovered, the problem was that clang-tidy by default treats .h files as C headers. Renaming it to myheaderlib.hpp fixed the issue. I'd still love to hear how to properly configure clang-tidy so that language can be specified regardless to the file extension.

Related