Skip to main content

IAR Embedded Workbench for RX 5.20

RED-unused-return-val

In this section:
Synopsis

There are unused function return values (other than overloaded operators).

Enabled by default

No

Severity/Certainty

Low/Medium

lowmedium.png
Full description

There are unused function return values (other than overloaded operators). This might be an error. The return value of a function should always be used. Overloaded operators are excluded; they should behave like the built-in operators. You can discard the return value of a function by using a (void) cast. This check is identical to MISRAC++2008-0-1-7, MISRAC2012-Rule-17.7.

Coding standards
CWE 252

Unchecked Return Value

MISRA C:2012 Rule-17.7

(Required) The value returned by a function having non-void return type shall be used

MISRA C++ 2008 0-1-7

(Required) The value returned by a function having a non-void return type that is not an overloaded operator shall always be used.

Code examples

The following code example fails the check and will give a warning:

int func ( int para1 )
{
   return para1;
}

void discarded ( int para2 )
{
  func(para2);         // value discarded - Non-compliant
}

The following code example passes the check and will not give a warning about this issue:

int func ( int para1 )
{
   return para1;
}

int not_discarded ( int para2 )
{
  if (func(para2) > 5){
    return 1;
  }
  return 0;
}