1

I'm having some trouble setting up clangd visual studio extension to support C23.

I use the following .clangd file

CompileFlags:
  Add: ["--std=c2x"]
  Compiler: gcc

In my root folder:

.clangd
src
  main.c

I can see from the extension logs that gcc correctly use the --std=c2x flag, but the following little code:

int main(int argc, char **argv) { 
  int *a = nullptr;
}

Raise the following error on nullptr: Use of undeclared identifier 'nullptr'clang(undeclared_var_use).

My clangd version:

$ clangd --version
clangd version 15.0.7
Features: linux
Platform: x86_64-pc-linux-gnu
Nullndr
  • 1,624
  • 1
  • 6
  • 24

1 Answers1

1

Clangd is built on clang and uses clang's C/C++ parser to parse your code.

This is the case even if you specify Compiler: gcc (the purpose of that option is mostly to help clangd find the right standard library headers).

That means that your ability to use certain language features depends on the version in which clang added support for them.

If you look at the "C23 implementation status" table in https://clang.llvm.org/c_status.html, you can see that "Introduce the nullptr constant" was added in clang 17. You're using clangd version 15, which is older than that.

Upgrading to clangd 17 will make this work as intended.

HighCommander4
  • 50,428
  • 24
  • 122
  • 194