Skip to main content

IAR Embedded Workbench for RH850 3.20.x

MISRAC2012-Rule-17.7

In this section:
Synopsis

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

Enabled by default

Yes

Severity/Certainty

Low/Medium

lowmedium.png
Full description

There are unused function return values (other than overloaded operators). This check is identical to RED-unused-return-val, MISRAC++2008-0-1-7, MISRAC++2023-0.1.2.

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.

MISRA C++ 2023 0.1.2

(Required) The value returned by a function shall 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;
}