Closed phcerdan closed 6 years ago
What happens if you the compile command to compile the file?
$ compdb list foo.h
<the compile command to copy>
$ clang++ <options...> foo.h
I had to clang++ "<options....>" foo.h
because parsing error for bash with a compiler declaration with parenthesis -DvtkAutoInit=3(a,b,c).
Beyond that unrelated problem, I just got a warning with clang++
clang-5.0: warning: treating 'c-header' input as 'c++-header' when in C++ mode, this behavior is deprecated [-Wdeprecated]
And zero warnings with c++
.
I have noticed that the only differences between test
and foo
entries in compile_commands.json
are: the file
key, and in command
, foo.h
lacks:
-o CMakeFiles/test.dir/test.cpp.o -c /path/src/test.cpp
Also, if I add a std header to foo.h I receive file not found from the LSP.
#include <iostream>
By the way, pinging this link here about proposing to cmake to generate info for headers: https://gitlab.kitware.com/cmake/cmake/issues/16285
Can you edit the command
key to add -x c++-header
, and see if that helps?
Maybe libclang think it is in C-mode and not C++, so it does not find C++-only headers like iostream
.
What mode is your Emacs when the file ends with .h
? By default it is c-mode
, not c++-mode
.
You can try to turn M-x c++-mode RET
manually and see if that changes anything.
I will try soon. I am on neovim though, with the plugin LanguageClient-neovim calling clangd
, I will check if the filetype of the buffer has any effect here, but I doubt it.
No difference with -x c++-header
I believe the issue is with your plugin/clangd, if clang works from the command line. If you look at the compile command, do you see anything wrong?
You are right, still receiving the warning from clang++ from the header, but clangd/LSP plugin is not doing it right. Closing, but I shall return in the future!
Using clangd (LSP) with the compile_commands.json generated by compdb after:
I am hitting
Error: expected identifier or '('
, I am guessing... is that because there is no main to compile the header? Any workaround for this?The
.cpp
files from the original compile_commands.json generated by cmake are working ok with clangd.A simplification of my header to reproduce the error.
Also note, maybe relevant that foo.h is included in a test.cpp using
catch
framework.