LLVM Discussion Forums

Header file heuristics issue

I have just encountered a problem with YCM (or more exactly clangd in a YCM-context) when opening a C++ header file. It happens to be a template declaration, the file extension is hpp, and there is no corresponding cpp file. The application contains C-files as well as C++ files. I have a compilation database, but the since the hpp file is only included, it does not appear in the compilation database. I use ARM cross-compiling and I got that working fine in general. The clangd log tells me:

Updating file /path/to/Header.hpp with command inferred from /other/path/to/arbitrary.c

where arbitrary.c is as the name implies a C-file that can indeed be found in my compilation database, but otherwise seems to be arbitrarily picked. And since it is a C-file, it does obviously not include the hpp file. The consequence is that the incorrect compiler flags are picked. In particular -std=c++17 is missing, although it is present in the compilation database for C++ files.
I have just checked another application with pretty much the same case, where what is inferred seems to be an arbitrary C++ file from the compilation database (that does not either include the hpp file). I am then lucky, and the hpp file is parsed correctly, which is why I had not noticed the problem earlier.
I have seen a few discussions on the clangd forums that could be related, but nothing really conclusive. I get the same behavior with clangd 10.0.0 and clangd 11.0.0 rc1.
Could I be so lucky that this would be a known issue with a known solution?

For anyone interested, discussion continues in https://github.com/clangd/clangd/issues/519