This kind of issue usually happen because of a parsing error during the analysis. What the analyzer looks at is the code where the problematic parts have been removed, and therefore it might not see where the value is read.
Here is for instance a possible scenario:
The header is not found during analysis
PK_VECTOR_s is therefore unknown
As a consequence, the type of squareLength is not properly deduced, and is replaced by an error type
The call to sqrt with an error type fails, and the call is removed from the analyzed code.
So the analyzer sees squareLength as never read.
Can you enable sonar.verbose=true and see if there are parsing errors related to this piece of code? Maybe you can solve them on your side (for instance if because of configuration, the header that describes PK_VECTOR_s is not correctly included), otherwise you can share it with us.
15:41:39.166 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:3 - ‘vector’ file not found
15:41:39.166 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:4 - ‘memory’ file not found
15:41:39.166 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:5 - ‘string’ file not found
15:41:39.166 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:6 - ‘numbers’ file not found
15:41:39.166 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:7 - ‘cmath’ file not found
15:41:39.166 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:23 - use of undeclared identifier ‘std’
15:41:39.170 DEBUG D:_1\10\s\source\Backend\src\geometry\GeometryApi.ixx:D:\Parasolid\381\x64_win\base\external_kernel.h:10 - ‘stddef.h’ file not found
The cleaned up signature static inline double Length(const PK_VECTOR_t& v) noexcept also didn’t helped (as expected).
You are missing <cmath>, which is where sqrt is defined. which can explain why the sqrt call is removed from the analysis…
It is in fact worse than that: You are missing the full standard library:
use of undeclared identifier ‘std’
So in addition to the issue you mentioned, there are probably numerous other issues that are no so visible but greatly decrease the quality of the analysis.
How do you configure the analysis? You say you are not using the build wrapper: Are you using autoscan or are you creating the compile_commands.json in another way? In that case, can you send it to us so we can have a look at it?
The build I reduced a lot, especially the private vcpkg registry and boost dependencies are removed. The now generated compile_commands.json is attached, in the verbose logs I still see the not found / undeclared identifiers. The file starts with
We would need the full logs to better understand what happens. At the start of the log are precious informations about how we deduce the system include paths when we analyze a MSVC project.
Attached you’ll find in the zip the full log of the code analyze step (10.txt) and some additional files I extracted from the build server which might help to understand what is going on.
For more files we should switch to a private channel.
There are different heuristics we use to determine where to look for system headers when working with MSVC. From what I see in the log, the one that is used in your case is an environment variable named INCLUDE.
It is apparently defined in your analysis environment, but not with the right value. On my machine, it looks like:
And it is typically set when running a script like VsDevCmd.bat or opening a Developper command prompt.
If you know why this variable is not correctly set in your analysis, maybe you can fix it, otherwise, we’ll need a reproducer for the file with the errors to get more info. I’m sending you a PM in case this is the next step.