Result of expressions should be used

  • UNUSED_EXPR
  • Code Quality
  • Medium, Low
  • cwe

This rule applies when the result of expression is not used.

Unused expression is dead so that it might imply a mistake or unnecessary code.

Note:

  1. Not applied for the code in try statement because unused expression is often used to check an exception, e.g. try { opener.document; } catch (e) {}.
  2. Not applied for void expression because it could be a programmer's intention that the value of the expression is not to be used.
  3. Not applied for property or variable accesses appearing as separate statements because they are usually harmless and often intended for various purposes.

Noncompliant Code Example

View with compliant examples side by side
function example1(x) {
    x + 1; // UNUSED_EXPR alarm
}

function example2(x, y) {
    x.p == y.p; // UNUSED_EXPR alarm
}

Compliant Code Example

View with noncompliant examples side by side
function example1(x) {
    return x + 1;
}

function example2(x, y) {
    x.p = y.p;
}

Version

This rule was introduced in DeepScan 1.0.0-alpha.

See

  • CWE-398

  • CWE-482

  • CWE-665

  • MISRA C:2004, Rule 14.2: All non-null statements shall either have at least one side effect however executed, or cause control flow to change

Was this documentation helpful?