MISRAC++2023-0.1.2
In this section:
Synopsis
(Required) The value returned by a function shall be used
Enabled by default
Yes
Severity/Certainty
Low/Medium

Full description
There are unused function return values (excluding overloaded operators) This check is identical to MISRAC++2008-0-1-7, MISRAC2012-Rule-17.7, RED-unused-return-val.
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;
}