8

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 .

Aaron Liu
  • 361
  • 2
  • 13
  • Your question is incomplete & lacking some information, like: Why can't you set the C++17 std flag to your clang compiler? what make-system are you using? – Tomer W Sep 17 '22 at 20:42
  • If you have something that isn't currently compiling successfully at all, I don't understand how it's even theoretically possible for you to turn it into working C++ code without a "try compiling it again, and this time it succeeds" step. – Nathan Pierson Sep 17 '22 at 20:49
  • 4
    Perhaps we should leave answering this question to people who know what `clangd` is and how to configure it. (Sorry, I’ve never used it, so I cannot offer any useful advice myself.) – Dúthomhas Sep 17 '22 at 20:54
  • 1
    @TomerW I'm not talking about the clang compiler, I"m talking about clangd. See my edit. – Aaron Liu Sep 17 '22 at 21:00
  • @NathanPierson The code compiles successfully, I meant to say recompile clangd. – Aaron Liu Sep 17 '22 at 21:01
  • 3
    https://clangd.llvm.org/config#compileflags – n. m. could be an AI Sep 17 '22 at 21:08
  • 1
    @n.1.8e9-where's-my-sharem. Read my question again, I believe it clearly states that I was asking for a solution that didn't require me to recompile clangd. – Aaron Liu Sep 17 '22 at 21:17
  • 2
    @AaronLiu did you read his link? It’s the correct answer to your question. Clangd accepts compiler flags to determine how to interpret the files. – Taekahn Sep 17 '22 at 23:07
  • See [this answer](https://stackoverflow.com/a/73596097/141719) to a similar question. No recompiling clangd required, just creating a config file in the root directory of your project. – HighCommander4 Sep 18 '22 at 04:22
  • I read it but misinterpreted it. Sorry. – Aaron Liu Sep 18 '22 at 15:28

1 Answers1

13

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]
Aaron Liu
  • 361
  • 2
  • 13
  • 4
    The config file is named `~/.clangd`. (ref: [*Configuration Files*](https://clangd.llvm.org/config#files)) – ynn Mar 26 '23 at 07:40