Page 1 of 1

Left border shows C errors in C++ header file

Posted: Fri Aug 02, 2019 6:23 pm
by Boksha
This may be a problem with clangd, but since I can't figure out how CodeLite talks to clangd (or how to change it) I'm hoping someone here might have a better understanding of what's going on.

When I create a project in CodeLite 13.0.0 with clangd as the language server and add a foo.h and a foo.cpp, and add some C++ specific code in the header file, I'm getting errors in the border of the header file indicating there's something wrong with the code. The only sense I can make of these errors is that whatever is analyzing the file (I think it's clangd, but I can't really find a way to make sure other than that the errors disappear when I turn the LSP off) thinks the header file contains C code.

The LLVM version I'm using is 7.1. Here's how I configured the Language Server plugin:

Image

and here's the errors I get in the header:

Image

The other two errros on line 6 and 12 are
6: expected ';' after top level declarator
12: expected identifier or '('

foo.cpp only contains

Code: Select all

#include "foo.h"

void bar()
{
}
and main.cpp is the standard "Hello world" generated by CodeLite. Compilation arguments for the project are "O2;-Wall;--std=c++14" (all other settings left at defaults)

Code completion also does not work in the header file. Some other observations that may help:
Code completion in foo.cpp does work; I can include <memory> and if I type "std::u" a pop up with unique_ptr appears. No errors either. (I also noticed that including foo.h, which includes <memory>, does not cause unique_ptr to show up in the autocomplete pop up)

Here are the contents of the compile_commands.json and compile_flags.txt CodeLite generated in the workspace directory:

Code: Select all

[{
  "file": "D:\\codelite_test_workspace_2\\main.cpp",
  "directory": "D:\\codelite_test_workspace_2",
  "command": "clang  -c D:\\codelite_test_workspace_2\\main.cpp -o D:\\codelite_test_workspace_2\\main.cpp.o -target x86_64-pc-windows-gnu -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++ -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++\\x86_64-w64-mingw32 -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++\\backward -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include-fixed -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\include -DNDEBUG -I. -I.  -O2  -Wall  --std=c++14"
 }, {
  "file": "D:\\codelite_test_workspace_2\\foo.h",
  "directory": "D:\\codelite_test_workspace_2",
  "command": "clang  -c D:\\codelite_test_workspace_2\\foo.h -o D:\\codelite_test_workspace_2\\foo.h.o -target x86_64-pc-windows-gnu -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++ -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++\\x86_64-w64-mingw32 -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++\\backward -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include-fixed -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\include -DNDEBUG -I. -I.  -O2  -Wall  --std=c++14"
 }, {
  "file": "D:\\codelite_test_workspace_2\\foo.cpp",
  "directory": "D:\\codelite_test_workspace_2",
  "command": "clang  -c D:\\codelite_test_workspace_2\\foo.cpp -o D:\\codelite_test_workspace_2\\foo.cpp.o -target x86_64-pc-windows-gnu -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++ -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++\\x86_64-w64-mingw32 -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include\\c++\\backward -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\lib\\gcc\\x86_64-w64-mingw32\\6.1.0\\include-fixed -IC:\\Program Files\\mingw-w64\\x86_64-6.1.0-win32-seh-rt_v5-rev0\\mingw64\\x86_64-w64-mingw32\\include -DNDEBUG -I. -I.  -O2  -Wall  --std=c++14"
 }]

Code: Select all

-IC:\Program
-ID:\codelite_test_workspace_2
-I"C:\Program Files\mingw-w64\x86_64-6.1.0-win32-seh-rt_v5-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\6.1.0\include\c++"
-I"C:\Program Files\mingw-w64\x86_64-6.1.0-win32-seh-rt_v5-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\6.1.0\include\c++\x86_64-w64-mingw32"
-I"C:\Program Files\mingw-w64\x86_64-6.1.0-win32-seh-rt_v5-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\6.1.0\include\c++\backward"
-I"C:\Program Files\mingw-w64\x86_64-6.1.0-win32-seh-rt_v5-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\6.1.0\include"
-I"C:\Program Files\mingw-w64\x86_64-6.1.0-win32-seh-rt_v5-rev0\mingw64\lib\gcc\x86_64-w64-mingw32\6.1.0\include-fixed"
-I"C:\Program Files\mingw-w64\x86_64-6.1.0-win32-seh-rt_v5-rev0\mingw64\x86_64-w64-mingw32\include"
-DNDEBUG
-target
x86_64-pc-windows-gnu
I'm noticing there are some problems with spaces in my mingw-w64 installation directory, but given that code completion does work for .cpp files, I don't think that's the cause of this particular issue. Changing 'clang' to 'clang++' and setting the json file to be read-only did not fix the problem.

Any idea how I can get C++ code completion to work for my headers?
Is there any other information I could provide that could help resolve this?
Thanks!

Re: Left border shows C errors in C++ header file

Posted: Sat Aug 03, 2019 10:00 pm
by eranif
Its a bug in clangd
The only workaround I found was to rename the headers into .hpp

Re: Left border shows C errors in C++ header file

Posted: Mon Aug 05, 2019 10:50 pm
by Boksha
I suspected as much, and I guess I'll go with the .hpp workaround for now. If I can find the time I might dive into LSP to see if I can get clangd to work in a smaller environment to reproduce this. Thanks for checking!