Using
SonarQube: 9.7.0.61563
build-wrapper, version 6.38 (linux-x86)
SonarScanner 4.7.0.2747
Ubuntu 20.04 + GCC 11.1.0
The following code raises S1110 (remove these useless parentheses) on line 25 Variant x = (z == 5);
- note that even though the parentheses are not mandatory for correct functionality using them greatly improves readability for which reason I think this usage should not be flagged by the scanner. In our case the expression is a bit more complicated with class and namespace resolution, this is just the minimal example I was able to build.
#include <iostream>
#include <vector>
#include <string>
using namespace std;
class Variant {
public:
Variant();
Variant(bool val) {
this->val = val;
}
void print() {
cout << this->val;
}
private:
bool val = 0;
};
int main() {
int z;
cout << "Input x "; //avoid any sort of optimization
cin >> z;
Variant x = (z == 5);
x.print();
}