- Operating system: Windows 11 pro
- SonarLint plugin version: v4.2.2
- Programming language you’re coding in: CPP
- VSCode version: 1.85.1
- cpp dev environment: clangd + CodeLLDB + cmakeTools
- clang version:
clang version 17.0.6
Target: x86_64-w64-windows-gnu
Thread model: posix - Is connected mode used:no
As per the documentation, I utilize CMake to generate the ‘compile_commands.json’ file. It is correct when I set the C++ standard to 17 .But when I use CPP20, SonarLint is unable to detect issues.
CPP code:
#include <iostream>
int x;
int t() {
int a = 0;
std::cout << "Hello, World!" << std::endl;
return 0;
}
cmakelists:
cmake_minimum_required(VERSION 3.28)
project(MyProject)
set(CMAKE_EXPORT_COMPILE_COMMANDS ON)
set(CMAKE_CXX_STANDARD 17)
set(CMAKE_CXX_STANDARD_REQUIRED ON)
file(GLOB SOURCE_FILES "src/*.cpp")
add_executable(MyProject ${SOURCE_FILES})
compile_commands.json:
[
{
"directory": "F:/person/cppLearn/build",
"command": "C:\\msys64\\clang64\\bin\\c++.exe -std=gnu++17 -o CMakeFiles\\MyProject.dir\\src\\main.cpp.obj -c F:\\person\\cppLearn\\src\\main.cpp",
"file": "F:\\person\\cppLearn\\src\\main.cpp",
"output": "CMakeFiles\\MyProject.dir\\src\\main.cpp.obj"
}
]
sonarLint output:
[Info - 21:26:33.336] Analyzing file “file:///f:/person/cppLearn/src/main.cpp”…
[Info - 21:26:33.737] Found 2 issues
when set cpp standard 20 and regen json
compile_commands.json:
[
{
"directory": "F:/person/cppLearn/build",
"command": "C:\\msys64\\clang64\\bin\\c++.exe -std=gnu++20 @CMakeFiles\\MyProject.dir\\src\\main.cpp.obj.modmap -o CMakeFiles\\MyProject.dir\\src\\main.cpp.obj -c F:\\person\\cppLearn\\src\\main.cpp",
"file": "F:\\person\\cppLearn\\src\\main.cpp",
"output": "CMakeFiles\\MyProject.dir\\src\\main.cpp.obj"
}
]
sonarlint output:
[Info - 21:29:41.776] Analyzing file “file:///f:/person/cppLearn/src/main.cpp”…
[Info - 21:29:41.814] Found 0 issues