VIM version
NVIM v0.2.2
Build type: Release
Operating System: macOS 10.13.4
Current Filetype: cpp
Available Linters: ['clang', 'clangcheck', 'clangtidy', 'cppcheck', 'cpplint', 'flawfinder', 'gcc']
Linter Aliases:
'gcc' -> ['g++']
Enabled Linters: ['clangtidy']
Linter Variables:
let g:ale_cpp_clangtidy_checks = ['*']
let g:ale_cpp_clangtidy_executable = 'clang-tidy'
let g:ale_cpp_clangtidy_options = ''
......
When current file is a C++ header file with extension ‘.h', ALE can recognize it is a C++ header file. But the clang-tidy seems to treat it as a C header file. As it find error like "'string' file not found" and "unknown type name 'namespace'".
If I rename the header file with extension '.hpp', then the clang-tidy can work properly. Do anyone has ideas to solve this problem?
This sounds like an issue with clang-tidy, but maybe there's an option ALE can pass to make clang-tidy understand that .h can be treated as C++ headers. There's a variable for controlling if headers are C or C++ files in Vim, which ALE could use.
Seems that we can use clangtidy's -x option to handle this.
let g:ale_cpp_clangtidy_options = '-x c++'
Also, it seems that CMake's compile_commands.json can not be used for C++ header files.
I did a PR for this recently, but I have closed for the following reason.
cpp is the default filetype for .h files in Vim. This means when you have a .h header file open under a C project (not C++) then ALE will think this file is -x c++ which is clearly wrong.
Instead I think the fix should introduce a new variable that switches on this behaviour for c++ header files.
I suggest:
g:cpp_clangtidy_h_is_hpp
Type: Number
Default: 0
what do you think?
I am also having an issue where I have C-compliant .h files that I do not want checked as .cpp files. Are there any workarounds at this time?
Hi Peter,
The issue I was describing above was not merged into master, so I'm not sure what issues you are experiencing. I think its best if you open a new issue so we can understand your situation better.
Thanks,
Rich.
Almost all C/C++ issues with flags should now be discussed in #3276, so a comprehensive solution can be found for most people, for automatically detecting flags.
Now ALE will tell clang-tidy that .h files are C++ files if the filetype is set to C++ in Vim.
This change actually broke things for me because without -- -x c++ clang-tidy will happily use my compile_commands.json, whereas when you pass compiler options, they appears to replace compile_commands.json entirely.
It would be good if there were an option controlling this, so it can be disabled. Or even better, if it's only enabled when you have no compile_commands.json - but that would mean having to check which may not be reasonable.
(For the moment I've just deleted those lines from clangtidy.vim locally.)
Most helpful comment
Seems that we can use clangtidy's -x option to handle this.