False positive with S1854


we noticed similar issues in C/C++. It looks like Sonar does not understand the initialization of a variable by a value returned from a function. See the attached screenshot for another example, where the variable is used as the input to another function in the line below. There are a lot more examples in our project.


Hi @colin1993,

I moved your post because we prefer to keep one subject per thread.

The issue that you are describing sounds more like a configuration error that is leading to a false positive.

initialization of a variable by a value returned from a function

We can understand this unless the configuration is wrong and we fail to parse the function call.
To check if it is the case, I suggest enabling S2260 and checking if around the false-positive there is a parsing error. you can read the detailed description here.

On my side, I can help you check if you have a config issue. Can you share the verbose log of successful analysis and the reproducer of one of the source files where you are facing the false-positive?


Hi @Abbas

We do indeed get a parsing error for some generated files. They are at the expected place though during build, as well as during analysis. I can provide a reproducer in a private message.


Hi @Abbas

Ok, it looks like that really was causing all the issues. We just had to make sure that all generated build artifacts are still present during the sonar scanner pass.

We can close the issue, thanks.


@colin1993 Yes, usually these kinds of false-positives indicate a bad configuration. The S2260(ParsingError) is a good indication of a configuration error. Glad you were able to fix it.


This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.