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: 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) {}.

Noncompliant Code Example

// Example 1
function f(x) {
    x + 1; // UNUSED_EXPR alarm
}

// Example 2
function g(x, y) {
    x.p == y.p; // UNUSED_EXPR alarm
}

Compliant Code Example

// Example 1
function f(x) {
    return x + 1;
}

// Example 2
function g(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