Search code examples
c++standardsclangd

Is there a way to specify the c++ standard of clangd without recompiling it?


I'm trying to use a feature in c++17(const lambdas) without having clangd error me. I've searched online and every answer tells me to recompile clangd with a flag. Is there truly no other way?

Edit: Clangd is not the compiler. It's a language server, which is a program made to be used with IDEs that basically checks your code for errors and warnings before compiling it. See https://clangd.llvm.org .


Solution

  • Answer inspired by n. 1.8e9-where's-my-share m.

    From https://clangd.llvm.org/config#compileflags:

    You can create a config file for clangd. In the config file, you can specify the compiler options mimicked. For my question, do this:

    CompileFlags:
      Add: [-std=c++20]
    

    Put the configuration file as .clangd in a shared parent directory of the files you want this to apply to. If you want it to apply for the entire user, make it a config.yaml file in an OS-specific directory:

    • Windows: %LocalAppData%\clangd\config.yaml, typically C:\Users\Bob\AppData\Local\clangd\config.yaml.
    • macOS: ~/Library/Preferences/clangd/config.yaml
    • Linux and others: $XDG_CONFIG_HOME/clangd/config.yaml, typically ~/.config/clangd/config.yaml.