This issue is present in both SonarQube version 9.1 and SonarLint version 4.38.0.36876
It seems like the sonar analyzer doesn’t understand the C++ alternative operators, even though they appear to have been a standard language feature since 98. Alternative operator representations - cppreference.com
Granted, MSVC hides these being the /permissive-
compiler flag. We compile our projects with msvc, and we use the corresponding flag to get the conformant behavior.
The results of this behavior might be something like this:
bool func(bool arg1, bool arg2) { return arg1 or arg2; }
In my case with a similar structure, the analyzer emits cpp:S1116 Rules explorer and points it at the semicolon, as if there’s an empty statement here. My conclusion based on this is that something about the operator representation isn’t understood like it should.
I realize that the usage of alternative operators relate to this post about the related rule that suggests to not use these operator representations. We have disabled this rule, because we like these operator representations. But I will go further and say that “because developers might be surprised” is not a good reason to emit a warning, at least not by default. That line of thinking is fully compatible with emitting a warning about code doing exactly what it says. I have previously run into such a case from msvc, where this warning is emitted on a function declared with override
. In a nutshell, such a warning effectively says “this might surprise you, but the code does exactly what it says it does”.
However, an actual good reason to emit a warning about usage of the alternative operator representations would be due to compatibility concerns, like I alluded to earlier. Which makes for a much better description. And the compatibility concerns are not necessarily isolated to MSVC itself. There is also a compatibility issue in clang-cl as reported in this bug report, which is not even resolved in a released version of LLVM yet.
Another small note about this is that the markdown used in the above snippet correctly highlights or
as a keyword.