Skip to content

"-std:c++20" isn't handled with cl.exe #9458

@tangtang95

Description

@tangtang95

Bug type: Language Service

Describe the bug

  • OS and Version: Windows 11 22000.675
  • VS Code Version: 1.68.1
  • C/C++ Extension Version: 1.10.7
  • Other extensions you installed (and if the issue persists after disabling them): CMake (0.0.17), CMake Language Support (0.0.4), CMakeTools (1.11.26), and .NET Install Tool for Extension Authors (1.5.0) [Note: All the other extensions are disabled]
  • A clear and concise description of what the bug is, including information about the workspace (i.e. is the workspace a single project or multiple projects, size of the project, etc).

Intellisense does not detect that you are using C++20 and the flag _HAS_CXX20 is set to false. However, the build of the C++ project works fine, only the syntax is detected as wrong. For completeness, this bug does not happen in the C/C++ extension version 1.9.8.

Steps to reproduce

  1. Create C++ CMake project with set(CMAKE_CXX_STANDARD 20)
  2. Try to use a C++20 feature such as span
  3. Gives the error identifier "span" is undefined C/C++(20)

Expected behavior

Intellisense should detect the project is using C++20 and there should be no error squibbles when using span. The correct behavior happens when using C/C++ extension version 1.9.8

Code sample and logs

  • Code sample

CMakeLists.txt

cmake_minimum_required(VERSION 3.15)
project(cmake_example VERSION 1.0)

set(CMAKE_CXX_STANDARD 20)
set(TARGET "cmake")

add_executable(${TARGET} "${CMAKE_SOURCE_DIR}/src/main.cpp")

src/main.cpp

#include <span>

using namespace std;

int main(int argc, char const *argv[])
{
    span<int> data;
    /* code */
    return 0;
}
  • Configurations in c_cpp_properties.json
{
    "configurations": [
        {
            "name": "Win32",
            "includePath": [
                "${workspaceFolder}/**"
            ],
            "defines": [
                "_DEBUG",
                "UNICODE",
                "_UNICODE"
            ],
            "windowsSdkVersion": "10.0.20348.0",
            "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe",
            "cStandard": "c17",
            "cppStandard": "c++20",
            "intelliSenseMode": "windows-msvc-x64",
            "configurationProvider": "ms-vscode.cmake-tools"
        }
    ],
    "version": 4
}
  • Logs from running C/C++: Log Diagnostics from the VS Code command palette
-------- Diagnostics - 16/6/2022, 15:19:51
Version: 1.10.7
Current Configuration:
{
    "name": "Win32",
    "includePath": [
        "${workspaceFolder}/**"
    ],
    "defines": [
        "_DEBUG",
        "UNICODE",
        "_UNICODE"
    ],
    "windowsSdkVersion": "10.0.20348.0",
    "compilerPath": "C:/Program Files/Microsoft Visual Studio/2022/Community/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe",
    "cStandard": "c17",
    "cppStandard": "c++20",
    "intelliSenseMode": "windows-msvc-x64",
    "configurationProvider": "ms-vscode.cmake-tools",
    "compilerPathIsExplicit": true,
    "cStandardIsExplicit": true,
    "cppStandardIsExplicit": true,
    "intelliSenseModeIsExplicit": true,
    "mergeConfigurations": false,
    "browse": {
        "path": [
            "${workspaceFolder}/**"
        ],
        "limitSymbolsToIncludedHeaders": true
    }
}
Custom browse configuration: 
{
    "browsePath": [
        "c:/users/tangtang/documents/cppprojects/cmake_example/build/cmakefiles/640c20b75fe1fe6a2c596525d1cede83",
        "c:/users/tangtang/documents/cppprojects/cmake_example/src"
    ],
    "compilerPath": "c:/program files/microsoft visual studio/2022/community/vc/tools/msvc/14.32.31326/bin/hostx86/x64/cl.exe",
    "compilerArgs": [],
    "compilerFragments": [
        "/DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd",
        "-std:c++20"
    ]
}
Custom configurations:
[ C:\Users\Tangtang\Documents\CppProjects\cmake_example\src\main.cpp ]
{
    "includePath": [],
    "defines": [],
    "compilerPath": "c:/program files/microsoft visual studio/2022/community/vc/tools/msvc/14.32.31326/bin/hostx86/x64/cl.exe",
    "compilerArgs": [],
    "compilerFragments": [
        "/DWIN32 /D_WINDOWS /GR /EHsc /Zi /Ob0 /Od /RTC1 -MDd",
        "-std:c++20"
    ]
}
Translation Unit Mappings:
[ C:\Users\Tangtang\Documents\CppProjects\cmake_example\src\main.cpp ]:
    C:\Users\Tangtang\Documents\CppProjects\cmake_example\src\main.cpp
    C:\Program Files\Microsoft Visual Studio\2022\Community\VC\Tools\MSVC\14.32.31326\include\span *
Translation Unit Configurations:
[ C:\Users\Tangtang\Documents\CppProjects\cmake_example\src\main.cpp ]:
    Process ID: 15888
    Memory Usage: 13 MB
    Compiler Path: c:/program files/microsoft visual studio/2022/community/vc/tools/msvc/14.32.31326/bin/hostx86/x64/cl.exe
    Includes:
        C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\VC\TOOLS\MSVC\14.32.31326\INCLUDE
        C:\PROGRAM FILES\MICROSOFT VISUAL STUDIO\2022\COMMUNITY\VC\TOOLS\MSVC\14.32.31326\ATLMFC\INCLUDE
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.20348.0\UM
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.20348.0\UCRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.20348.0\SHARED
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.20348.0\WINRT
        C:\PROGRAM FILES (X86)\WINDOWS KITS\10\INCLUDE\10.0.20348.0\CPPWINRT
    Defines:
        WIN32
        _WINDOWS
    Standard Version: ms_c++14
    IntelliSense Mode: windows-msvc-x64
    Other Flags:
        --rtti
Total Memory Usage: 13 MB

------- Workspace parsing diagnostics -------
Number of files discovered (not excluded): 4937

Metadata

Metadata

Assignees

Labels

Feature: ConfigurationAn issue related to configuring the extension or IntelliSensebugfixedCheck the Milestone for the release in which the fix is or will be available.quick fixregressionA bug that didn't exist in a previous release

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions