Home

Noreturn

Noreturn refers to a property of a function indicating that it does not return to the caller. When such a function is invoked, control flow ends at the function, typically by terminating the program, throwing an exception in languages that use exceptions, or transferring control elsewhere in a non-returning manner. The concept is important for both correctness and optimization, as compilers can assume that code following a noreturn call is unreachable.

In different languages and environments, noreturn is expressed with several syntaxes. In C11 and later, a function

Notes and caveats include that noreturn is a promise by the programmer or standard library implementer. If

Common uses include terminating a program path after reporting an unrecoverable error, ending a thread, or

can
be
declared
as
_Noreturn,
for
example:
_Noreturn
void
fatal(void);
In
GCC
and
Clang
extensions
for
C,
the
attribute
__attribute__((noreturn))
is
used,
such
as:
void
fatal(void)
__attribute__((noreturn));
In
C++11
and
later,
the
standard
name
[[noreturn]]
can
be
applied
to
a
function:
[[noreturn]]
void
fatal();
In
practice,
many
standard
library
routines
that
terminate
a
program
(such
as
exit
or
abort)
are
noreturn.
a
noreturn
function
unexpectedly
returns,
behavior
is
undefined
in
languages
where
the
contract
is
not
fulfilled.
Noreturn
also
interacts
with
compiler
diagnostics:
compilers
may
warn
if
control
can
flow
off
the
end
of
a
noreturn
function
or
if
a
non-noreturn
function
appears
not
to
return
where
required.
signaling
a
non-returning
error
path.
The
concept
differs
from,
but
is
related
to,
exceptions
and
to
languages
that
use
a
distinct
never
type
(as
in
some
languages)
to
represent
non-returning
computations.