cpp:S1121 false-positive with assignment explicitly enclosed in parentheses

  • What language is this for?
    C++

  • Which rule?
    cpp:S1121 (“Assignments should not be made from within conditions”)

  • Why do you believe it’s a false-positive/false-negative?
    Because the rule text says “This rule ignores assignments explicitly enclosed in parentheses.”, and the rule doesn’t ignore them.

  • SonarQube for VS 2026, v10.1.0.16642 in connected mode with SonarQube Server

static void foo(int) {}

int main() {
    int a = 0;
    foo((a = 1));
    [[maybe_unused]] int b = a;
}

Hi,

The current version of SonarQube for Visual Studio (formerly SonarLint) is 10.2.3. Can you upgrade and see if this is still replicable?

 
Thx,
Ann

Yes, it is.

Hi,

Thanks for confirming. I’ve flagged this for the language experts.

 
Ann

Thanks. By the way, it’s unclear to me why this exact rule triggers at all, given that it considers “conditionals” which my call is not.

Hi @bers,

We are aware of issues with this rule… :frowning:
… and fixes should come soon! :slight_smile:

First, the rule description did not fit the implementation. The goal is to detect assignments that are sub-expressions, so not only in conditionals. So, without the double parentheses, your code would still be non-compliant.

Then, the implementation itself had several shortcoming, including incorrect detection of assignments enclosed in parentheses. This has been fixed too.

Both fixes should be available in our next release.