Since I have struggled these warnings/errors for so long. I decided to ask this question and answer myself for late comers.
Extension: vscode-clangd
'auto' type specifier is a C++11 extensionclang(-Wc++11-extensions)or any "grammar belong to C++11 or later" error. How to set default C/C++ standard in vscode-clangd?Invalid argument '-std=c99' not allowed with 'Objective-C++'or any header extension .h interpreted as C/C++ conflicting with your standard. How to deal with this annoying bugs?
Solutions
Three ways
compile_flags.txt:complie_commands.jsonby a build system like CMake, which can be enabled by adding this to your CMakeLists.txt file:If no compilation database(
compile_flags.txt/complie_commands.json) is found, you can do this in your vscode:cmd/ctrl + shift + p: Preferences: Open User Settings (JSON)settings.jsonfile:cmd/ctrl + shift + p: clangd: Restart language serverYou just can't set C & C++ standard into your
clangd.fallbackFlagsat the same time or it will conflict with each other. Two way to fix this:-x.clangdinto your project root with these lines:Explaination
clangd first check for a compilation database in the directory containing the source file, and then walk up into parent directories until we find one. The compilation database can be:
a file named
compile_commands.jsonlisting commands for each file. Usually generated by a build system like CMake.a file named
compile_flags.txtlisting flags to be used for all files. Typically hand-authored for simple projects.If no compilation database is found, use
clangd.fallbackFlags.