<div dir="ltr">Just landed r329582 which has does some guessing when there's no compile command available.<div>Please try it out!<br><div><br></div><div>Related changes I'd still like to make:</div><div> - parse *.h as obj-c++ when there's no compilation database at all (out for review)</div><div> - inject a diagnostic when we're using a fallback/guessed command for diagnostics</div></div></div><br><div class="gmail_quote"><div dir="ltr">On Tue, Apr 3, 2018 at 12:03 AM Jan Včelák <<a href="mailto:jv@fcelda.cz">jv@fcelda.cz</a>> wrote:<br></div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Thank you all for the responses.<br>
<br>
On Mon, Mar 26, 2018 at 10:22 AM, Sam McCall wrote:<br>
> Yeah, this is a known missing feature - guessing the right compile flags for<br>
> headers.<br>
> If you have a compilation database (e.g. compile_commands.json) that<br>
> provides compile commands for headers, then clangd works as expected.<br>
> However most build systems don't provide this information. (Bazel, for one,<br>
> does).<br>
<br>
I see. That makes perfect sense. We use cmake which doesn't export<br>
compile commands for headers unfortunately.<br>
<br>
> When there's no compile command provided, we fall back to 'clang $filename'.<br>
> Clang treats .h files as C.<br>
> But it's also missing a bunch of other information: include paths, defines<br>
> etc that are likely required to get useful results.<br>
> So I don't think just diverging from clang here will actually help many<br>
> projects (feel free to try this out by editing compile_commands.json - if<br>
> this works for you it'd be good to know).<br>
<br>
I have tried adding a compile_commands.json entry for a header with<br>
flags matching the cpp file. The headers were recognized as C++<br>
because the former errors on keywords like namespace were gone but<br>
something was still wrong. Some STL declarations were not found -<br>
std::shared_ptr for instance. Running the compiler command from<br>
terminal showed 'clang-6.0: warning: treating 'c-header' input as<br>
'c++-header' when in C++ mode, this behavior is deprecated<br>
[-Wdeprecated]' which made me try adding '-x c++'. That fixed the<br>
remaining problem but it's strange as the code was already recognized<br>
as C++ and the command contains explicit -std=c++14 option.<br>
<br>
> What can we do then? A few ideas:<br>
<br>
There are some good suggestions. I'm sure you will find some good<br>
default and I'm looking forward to try it out. I can just confirm that<br>
the heuristic used by YouCompleteMe is quite nice because that's what<br>
I've been using so far. It's not optimal but it works reasonably well.<br>
<br>
Cheers,<br>
<br>
Jan<br>
</blockquote></div>