Skip to content

Intellisense does not assume C23 when using CMake with c_std_23 #14560

Description

@robindegen

Environment

  • OS and Version: Arch
  • VS Code Version: C/C++ prerelease (1.33.2?)
  • C/C++ Extension Version: C23

Bug Summary and Steps to Reproduce

Bug Summary:

Steps to reproduce:

  1. Create a basic Cmake file using c_std_23 as the language version. Then generate with compile commands.
  2. In VSCode, things like nullptr, bool etc are not at all recognized.

What is really happening is that CMake correctly assumes that C23 is the standard for GCC and completely omits -std=c23 (or gnu23) from the command-line in compile-commands.json. Hence, the language server does not know that C23 is used and just falls back to C99 (likely). Clangd shows this exact same behavior. C99 is no longer a correct default to fall back to. Hasn't been for a while.

Expected behavior:
Intellisense should be compiler version aware and know that C23 is implicit if no flags are specified.

Configuration and Logs

The fix is just to specify C23 in c_cpp_properties.json. If this file is not provided; intellisense defaults are incorrect:

{
    "version": 4,
    "configurations": [
        {
            "name": "Linux",
            "compilerPath": "/usr/bin/cc",
            "cStandard": "c23",
            "intelliSenseMode": "linux-gcc-x64",
            "compileCommands": "${workspaceFolder}/build/compile_commands.json"
        }
    ]
}

And then suddenly intellisense has basic C23 support (somewhat.. at least it doesn't complain anymore)

Other Extensions

No response

Additional context

No response

Metadata

Metadata

Assignees

Type

Fields

No fields configured for Bug.

Projects

Status
No status

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions