ccls
ccls copied to clipboard
conversion operator of a template class reports invalid name
Observed behavior
ccls reports invalid name for the operator in this code:
template <typename TYPE>
struct Foo {
operator Foo<const TYPE>() {
return 0;
}
};
It produces this json message:
{
"jsonrpc": "2.0",
"id": 2,
"result": [
{
"name": "Foo",
"detail": "struct Foo {}",
"kind": 23,
"range": {
[[[snip]]]
},
"selectionRange": {
[[[snip]]]
},
"children": [
{
"name": "operator Foo<const TYPE>()\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000\u0000",
"detail": "operator Foo<const TYPE>()",
"kind": 6,
"range": {
[[[snip]]]
},
"selectionRange": {
[[[snip]]]
},
"children": []
}
]
}
]
}
Note the embedded \0
characters in the name for the operator.
I debugged the issue a little bit, and the problem is that in IndexDataConsumer::setName
, detailed_name
contains a string which has TYPE
as the template parameter, but short_name
contains type-parameter-0-0
. So later when short_name_size
is used to index detailed_name
, it creates a std::string_view
which over-reads the detailed_name
string.
Note: if I remove const
, then it works OK.
Expected behavior
name
should be properly reported.
Steps to reproduce
This happens for me with lsp-mode in emacs. Save my example cpp file, and load it into emacs with lsp-mode. A json parse error will be generated for the name because of the \0
characters:
Warning (lsp-mode): Failed to parse the following chunk:
[[[snip, the bad json is printed here]]]
with message (json-parse-error \u0000 is not allowed without JSON_ALLOW_NUL <callback> 1 361 361) Disable showing Disable logging
System information
- ccls version: 0.20210330-3-g92eba29a
- clang version: 11
- OS: Linux
- Editor: emacs
- Language client (and version): lsp-mode