ccls
ccls copied to clipboard
Invalid ccls errors
Observed behavior
Given this code:
#include <iostream>
#include <memory>
struct S {
auto hello() -> void {
std::cout << "hello\n";
}
};
int main() {
auto s = std::make_shared<S>();
s->hello();
}
I get the error messages: On line 7:
[ccls 2] [E] invalid operands to binary expression ('std::__1::ostream' (aka 'int') and 'const char [7]')
On line 12:
[ccls 2] [E] no matching function for call to 'make_shared'
Like so:
Which is strange, because it is valid and code compiles fine and executes fine. I'm not sure what is the source of those errors. Perhaps I have my ccls somehow misconfigured - code like this doesn't pop up any errors, though it should fail at invalid method:
#include <iostream>
#include <string>
int main() {
std::cout << std::string().len2();
}
Going to the definition works of std::string
works fine (?), I get straight to /Library/Developer/CommandLineTools/usr/include/c++/v1/iosfwd
. Perhaps it should be the string header and not the forward declaration? No idea how could I enforce it though. The member methods of string
class are not suggested.
Expected behavior
No errors are highlighted given the sample code and members of std::string
are suggested.
System information
- ccls version:
ccls-0.20201219
installed withbrew
- clang version:
Apple clang version 12.0.0 (clang-1200.0.32.28)
- OS: MacOS Catalina 10.15.7
- Editor: NVIM v0.4.4
- Language client (and version):
coc.nvim 0.0.80-fff2a86b16
ccls config
"languageserver": {
"ccls": {
"command": "ccls",
"filetypes": ["c", "cpp", "objc", "objcpp"],
"rootPatterns": [".ccls", "compile_commands.json", ".vim/", ".git/", ".hg/"],
"initializationOptions": {
"client": {
"snippetSupport": true
},
"cache": {
"directory": "/tmp/ccls"
},
"clang": {
"resourceDir": "/Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/clang/12.0.0/include",
"extraArgs": [
"-std=c++2a",
"-isysroot", "/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/include",
"-isystem", "/Library/Developer/CommandLineTools/usr/include/c++/v1",
]
}
}
}
}
Possible issue (not sure) - ccls --version
says clang version 11.0.0
though my default one is 12.0.0.
meet same issue with AUR ccls, and I solved it by building ccls from source.
@rhcher thanks for the suggestion, I tried it out and the error persists (though at least now the ccls --version
shows a proper tag, with brew
I had unknown
)
❯ ccls --version
ccls version 0.20201219-3-g40145807
clang version 11.0.0
Maybe you can specify the clang version when configruating with adding this: -DCMAKE_CXX_COMPILER=clang++
cmake -H. -BRelease -DCMAKE_BUILD_TYPE=Release -DCMAKE_PREFIX_PATH=/usr/local/Cellar/llvm/11.0.0_1/lib/cmake -DCMAKE_CXX_COMPILER=(which clang++)
cmake --build Release --target install
I'm configuring it and installing using the commands above. Still bogus errors from the standard library.
Same issue here
Also got the same issue after upgrading my brew packages. Installing the unstable (--HEAD) version of ccls resolved it for me.