All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.sonar.l10n.java.rules.squid.AssignmentInSubExpressionCheck.html Maven / Gradle / Ivy

The newest version!

Assignments within sub-expressions are hard to spot and therefore make the code less readable.

It is also a common mistake to write = when == was meant.

Ideally, expressions should not have side-effects.

Noncompliant Code Example

doSomething(i = 42);

Compliant Solution

i = 42;
doSomething(i);   

or

doSomething(i == 42);  // Perhaps in fact the assignment operator was expected

Exceptions

Assignments in while statement conditions, and assignments enclosed in relational expressions are allowed.

See

  • MISRA C:2004, 13.1 - Assignment operators shall not be used in expressions that yield a Boolean value
  • MISRA C++:2008, 6-2-1 - Assignment operators shall not be used in sub-expressions
  • MISRA C:2012, 13.4 - The result of of an assignment operator should not be used
  • MITRE, CWE-481 - Assigning instead of Comparing




© 2015 - 2025 Weber Informatics LLC | Privacy Policy