﻿# V2660\. MISRA\. A function declared with a \_Noreturn specifier should not return to its caller\.

This diagnostic rule is based on the [MISRA](https://misra.org.uk/) \(Motor Industry Software Reliability Association\) software development guidelines\.

This diagnostic rule is relevant only for C\.

The `_Noreturn` specifier prompts the compiler that the function does not return control flow to the caller on any execution path\. A violation of this contract leads to undefined behavior \(C11, section [6\.7\.4\.8](https://open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf#page=144), [Annex J2](https://open-std.org/JTC1/SC22/WG14/www/docs/n1570.pdf#page=580)\)\.

Here is an example of erroneous code:

```cpp
_Noreturn void foo(int x)
{
  if (x != 0)
    abort();
}
```

In this example, when the value of the `x` parameter is zero, `foo` returns control flow to the caller function\. This contradicts the `_Noreturn` specifier\.

The fixed code:

```cpp
_Noreturn void foo(int x)
{
  abort();
}
```