Revert autoupdate's revert.
[gnulib.git] / doc / noreturn.texi
blob62bdbde1fd06d727defbab5d022d0d866a2094f1
1 @c GNU noreturn, stdnoreturn modules documentation
3 @c Copyright (C) 2019--2020 Free Software Foundation, Inc.
5 @c Permission is granted to copy, distribute and/or modify this document
6 @c under the terms of the GNU Free Documentation License, Version 1.3 or
7 @c any later version published by the Free Software Foundation; with no
8 @c Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts.  A
9 @c copy of the license is at <https://www.gnu.org/licenses/fdl-1.3.en.html>.
11 @node Non-returning Functions
12 @section Non-returning Functions
14 @cindex @code{_Noreturn}
15 @cindex @code{noreturn}
16 @cindex @code{stdnoreturn}
17 A "non-returning" function is a function which cannot return normally.
18 It can transfer control only through @code{longjmp()}, @code{throw}
19 (in C++), or similar mechanisms.  The most prominent function of this
20 class is the @code{abort} function.  Non-returning functions are
21 declared with a @code{void} return type.
23 It helps the compiler's ability to emit sensible warnings, following
24 data-flow analysis, to declare which functions are non-returning.
26 Gnulib has two modules that support such a declaration:
28 @itemize @bullet
29 @item
30 The @samp{stdnoreturn} module.  It provides a way to put this
31 declaration at function declarations and function definitions, but not
32 in function pointer types.  The identifier to use is @code{_Noreturn}
33 or @code{noreturn}; @code{_Noreturn} is to be preferred because
34 @code{noreturn} is a no-op on some platforms.  The include file is
35 @code{<stdnoreturn.h>}.
37 @item
38 The @samp{noreturn} module.  It provides a way to put this declaration
39 at function declarations, at function definitions, and in function
40 pointer types.  The identifiers to use are:
41 @itemize -
42 @item
43 @code{_GL_NORETURN_FUNC} for use in function declarations and function
44 definitions.
45 @item
46 @code{_GL_NORETURN_FUNCPTR} for use on function pointers.
47 @end itemize
48 @noindent
49 The include file is @code{<noreturn.h>}.
50 @end itemize
52 Which of the two modules to use?  If the non-returning functions you
53 have to declare are unlikely to be accessed through function pointers,
54 you should use module @code{stdnoreturn}; otherwise the module
55 @code{noreturn} provides for better data-flow analysis and thus for
56 better warnings.
58 For a detailed description of the @code{stdnoreturn} module, see
59 @ref{stdnoreturn.h}.