False positive clangd diagnostic errors

How do I figure out why it’s complaining about this? I’m flooded with false positives like this so the diagnostics are just noise to me atm.

relevant line for this file from the compile_commands.json

  "command": "/usr/bin/clang    -O3 -DNDEBUG   -std=gnu++2a -o CMakeFiles/CCI.dir/ch8.cpp.o -c /mnt/c/CCI/ch8.cpp",

Have you looked at the log file? The log file is very helpful for figuring out this sort of thing. Set log=verbose in the nvim lsp setup for clangd. Within the log file (which is in ~/.cache/nvim/ for me) will be the exact command clangd used to produce the error. You can examine that command and see what’s missing or wrong.
I had lots of false diagnostic message as well, and what fixed it for me was to create a .clangd file in the root dir and add additional compile flags (mostly to tell clangd where to find my system headers, but also to give it details about the architecture)
The clangd site has some documentation about the .clangd configuration file.

Edit: here’s the page on .clangd config files: Configuration

2 Likes

how are you generating your compile_commands.json file? I usually do it from either cmake or compiledb python module depending on the project. Never had such errors before