Skip to main content

IAR Embedded Workbench for Arm 9.70.x

MISRAC++2023-9.6.5

In this section:
Synopsis

(Required) A function with non-void return type shall return a value on all paths

Enabled by default

Yes

Severity/Certainty

Medium/High

mediumhigh.png
Full description

For some execution paths, no return statements are executed in functions with a non-void return type. This check is identical to MISRAC++2008-8-4-3, MISRAC2004-16.8, MISRAC2012-Rule-17.4, SPC-return.

Coding standards
CERT MSC37-C

Ensure that control never reaches the end of a non-void function

MISRA C:2004 16.8

(Required) All exit paths from a function with non-void return type shall have an explicit return statement with an expression.

MISRA C:2012 Rule-17.4

(Mandatory) All exit paths from a function with non-void return type shall have an explicit return statement with an expression

MISRA C++ 2008 8-4-3

(Required) All exit paths from a function with non-void return type shall have an explicit return statement with an expression.

Code examples

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

#include <stdio.h>

int example(void) {
  int x;

  scanf("%d",&x);

  if (x > 10) {
    return 10;
  }
}

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

#include <stdio.h>

int example(void) {
  int x;

  scanf("%d",&x);

  if (x > 10) {
    return 10;
  }

  return 0;
}