cpp:S1110 Potential False Positive with Constructor

build-wrapper, version 6.38 (linux-x86)
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 {
                Variant(bool val) {
                        this->val = val;

                void print() {
                        cout << this->val;
                bool val = 0;

int main() {
        int z;
        cout << "Input x "; //avoid any sort of optimization
        cin >> z;
        Variant x = (z == 5);

Hello @Adrianh,

Thank you for your report and your minimal example that was really helpful to reproduce the issue. I agree with you, the usage you are describing should not be reported.
I have created a ticket to fix this false positive: CPP-3988.

Have a nice day,

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