Skip to content

Commit 494fd23

Browse files
committed
[except.terminate] Move the 'terminate' function to [basic.start]
Now that the terminate function is more general than just failures of the exception machinery, it belongs with Start and termination.
1 parent 8c718ea commit 494fd23

File tree

3 files changed

+126
-135
lines changed

3 files changed

+126
-135
lines changed

source/basic.tex

Lines changed: 121 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7194,5 +7194,126 @@
71947194
\libheaderref{cstdlib} terminates the program without executing any destructors
71957195
and without calling
71967196
the functions passed to \tcode{std::atexit()} or \tcode{std::at_quick_exit()}.%
7197+
7198+
\rSec3[except.terminate]{The \tcode{std::terminate} function}
7199+
7200+
\pnum
7201+
\indextext{\idxcode{terminate}}%
7202+
Some errors in a program cannot be recovered from, such as when an exception
7203+
is not handled or a \tcode{std::thread} object is destroyed while its thread
7204+
function is still running. In such cases,
7205+
the function \tcode{std::terminate}\iref{exception.terminate} is invoked.
7206+
\begin{note}
7207+
These situations are:
7208+
\indextext{\idxcode{terminate}!called}%
7209+
\begin{itemize}
7210+
\item%
7211+
when the exception handling mechanism, after completing
7212+
the initialization of the exception object
7213+
but before
7214+
activation of a handler for the exception\iref{except.throw},
7215+
calls a function that exits
7216+
via an exception, or
7217+
7218+
\item%
7219+
when the exception handling mechanism cannot find a handler for a thrown exception\iref{except.handle}, or
7220+
7221+
\item when the search for a handler\iref{except.handle} encounters the
7222+
outermost block of a function
7223+
with a non-throwing exception specification\iref{except.spec}, or
7224+
7225+
\item%
7226+
when the destruction of an object during stack unwinding\iref{except.ctor}
7227+
terminates by throwing an exception, or
7228+
7229+
\item%
7230+
when initialization of a non-block
7231+
variable with static or thread storage duration\iref{basic.start.dynamic}
7232+
exits via an exception, or
7233+
7234+
\item%
7235+
when destruction of an object with static or thread storage duration exits
7236+
via an exception\iref{basic.start.term}, or
7237+
7238+
\item%
7239+
when execution of a function registered with
7240+
\tcode{std::atexit} or \tcode{std::at_quick_exit}
7241+
exits via an exception\iref{support.start.term}, or
7242+
7243+
\item%
7244+
when a
7245+
\grammarterm{throw-expression}\iref{expr.throw}
7246+
with no operand attempts to rethrow an exception and no exception is being
7247+
handled\iref{except.throw}, or
7248+
7249+
\item%
7250+
when the function \tcode{std::nested_exception::rethrow_nested} is called for an object
7251+
that has captured no exception\iref{except.nested}, or
7252+
7253+
\item%
7254+
when execution of the initial function of a thread exits via
7255+
an exception\iref{thread.thread.constr}, or
7256+
7257+
\item%
7258+
for a parallel algorithm whose \tcode{ExecutionPolicy} specifies such
7259+
behavior\iref{execpol.seq,execpol.par,execpol.parunseq},
7260+
when execution of an element access function\iref{algorithms.parallel.defns}
7261+
of the parallel algorithm exits via an exception\iref{algorithms.parallel.exceptions}, or
7262+
7263+
\item%
7264+
when the destructor or the move assignment operator is invoked on an object
7265+
of type \tcode{std::thread} that refers to
7266+
a joinable thread\iref{thread.thread.destr,thread.thread.assign}, or
7267+
7268+
\item%
7269+
when a call to a \tcode{wait()}, \tcode{wait_until()}, or \tcode{wait_for()}
7270+
function on a condition variable\iref{thread.condition.condvar,thread.condition.condvarany}
7271+
fails to meet a postcondition, or
7272+
7273+
\item%
7274+
when a callback invocation exits via an exception
7275+
when requesting stop on
7276+
a \tcode{std::stop_source} or
7277+
a \tcode{std::in\-place_stop_source}\iref{stopsource.mem,stopsource.inplace.mem},
7278+
or in the constructor of
7279+
\tcode{std::stop_callback} or
7280+
\tcode{std::inplace_stop_callback}\iref{stopcallback.cons,stopcallback.inplace.cons}
7281+
when a callback invocation exits via an exception, or
7282+
7283+
\item%
7284+
when a \tcode{run_loop} object is destroyed
7285+
that is still in the \tcode{running} state\iref{exec.run.loop}, or
7286+
7287+
\item%
7288+
when \tcode{unhandled_stopped} is called on
7289+
a \tcode{with_awaitable_senders<T>} object\iref{exec.with.awaitable.senders}
7290+
whose continuation is not a handle to a coroutine
7291+
whose promise type has an \tcode{unhandled_stopped} member function.
7292+
7293+
\end{itemize}
7294+
7295+
\end{note}
7296+
7297+
\pnum
7298+
\indextext{\idxcode{terminate}}%
7299+
In the situation where no matching handler is found, it is
7300+
\impldef{stack unwinding before invocation of \tcode{std::terminate}}
7301+
whether or not the stack is unwound
7302+
before \tcode{std::terminate} is invoked.
7303+
In the situation where the search for a handler\iref{except.handle} encounters the
7304+
outermost block of a function
7305+
with a non-throwing exception specification\iref{except.spec}, it is
7306+
\impldef{whether stack is unwound before invoking the function \tcode{std::terminate}
7307+
when a \tcode{noexcept} specification is violated}
7308+
whether the stack is unwound, unwound partially, or not unwound at all
7309+
before the function \tcode{std::terminate} is invoked.
7310+
In all other situations, the stack shall not be unwound before
7311+
the function \tcode{std::terminate}
7312+
is invoked.
7313+
An implementation is not permitted to finish stack unwinding
7314+
prematurely based on a determination that the unwind process
7315+
will eventually cause an invocation of the function
7316+
\tcode{std::terminate}.
7317+
71977318
\indextext{program!termination|)}
71987319
\indextext{program execution|)}

source/exceptions.tex

Lines changed: 0 additions & 135 deletions
Original file line numberDiff line numberDiff line change
@@ -747,139 +747,4 @@
747747
exception object and will have effect should that object be rethrown.%
748748
\indextext{exception handling!handler!match|)}%
749749
\indextext{exception handling!handler|)}
750-
751-
\rSec1[except.special]{Special functions}
752-
753-
\rSec2[except.special.general]{General}
754-
755-
\pnum
756-
The function \tcode{std::terminate}\iref{except.terminate}
757-
is used by the exception
758-
handling mechanism for coping with errors related to the exception handling
759-
mechanism itself.
760-
The function \tcode{std::uncaught_exceptions}\iref{uncaught.exceptions}
761-
reports how many exceptions are uncaught in the current thread.
762-
The function \tcode{std::current_exception}\iref{propagation} and the class
763-
\tcode{std::nested_exception}\iref{except.nested} can be used by a program to
764-
capture the currently handled exception.
765-
766-
\rSec2[except.terminate]{The \tcode{std::terminate} function}
767-
768-
\pnum
769-
\indextext{\idxcode{terminate}}%
770-
Some errors in a program cannot be recovered from, such as when an exception
771-
is not handled or a \tcode{std::thread} object is destroyed while its thread
772-
function is still running. In such cases,
773-
the function \tcode{std::terminate}\iref{exception.terminate} is invoked.
774-
\begin{note}
775-
These situations are:
776-
\indextext{\idxcode{terminate}!called}%
777-
\begin{itemize}
778-
\item%
779-
when the exception handling mechanism, after completing
780-
the initialization of the exception object
781-
but before
782-
activation of a handler for the exception\iref{except.throw},
783-
calls a function that exits
784-
via an exception, or
785-
786-
\item%
787-
when the exception handling mechanism cannot find a handler for a thrown exception\iref{except.handle}, or
788-
789-
\item when the search for a handler\iref{except.handle} encounters the
790-
outermost block of a function
791-
with a non-throwing exception specification\iref{except.spec}, or
792-
793-
\item%
794-
when the destruction of an object during stack unwinding\iref{except.ctor}
795-
terminates by throwing an exception, or
796-
797-
\item%
798-
when initialization of a non-block
799-
variable with static or thread storage duration\iref{basic.start.dynamic}
800-
exits via an exception, or
801-
802-
\item%
803-
when destruction of an object with static or thread storage duration exits
804-
via an exception\iref{basic.start.term}, or
805-
806-
\item%
807-
when execution of a function registered with
808-
\tcode{std::atexit} or \tcode{std::at_quick_exit}
809-
exits via an exception\iref{support.start.term}, or
810-
811-
\item%
812-
when a
813-
\grammarterm{throw-expression}\iref{expr.throw}
814-
with no operand attempts to rethrow an exception and no exception is being
815-
handled\iref{except.throw}, or
816-
817-
\item%
818-
when the function \tcode{std::nested_exception::rethrow_nested} is called for an object
819-
that has captured no exception\iref{except.nested}, or
820-
821-
\item%
822-
when execution of the initial function of a thread exits via
823-
an exception\iref{thread.thread.constr}, or
824-
825-
\item%
826-
for a parallel algorithm whose \tcode{ExecutionPolicy} specifies such
827-
behavior\iref{execpol.seq,execpol.par,execpol.parunseq},
828-
when execution of an element access function\iref{algorithms.parallel.defns}
829-
of the parallel algorithm exits via an exception\iref{algorithms.parallel.exceptions}, or
830-
831-
\item%
832-
when the destructor or the move assignment operator is invoked on an object
833-
of type \tcode{std::thread} that refers to
834-
a joinable thread\iref{thread.thread.destr,thread.thread.assign}, or
835-
836-
\item%
837-
when a call to a \tcode{wait()}, \tcode{wait_until()}, or \tcode{wait_for()}
838-
function on a condition variable\iref{thread.condition.condvar,thread.condition.condvarany}
839-
fails to meet a postcondition, or
840-
841-
\item%
842-
when a callback invocation exits via an exception
843-
when requesting stop on
844-
a \tcode{std::stop_source} or
845-
a \tcode{std::in\-place_stop_source}\iref{stopsource.mem,stopsource.inplace.mem},
846-
or in the constructor of
847-
\tcode{std::stop_callback} or
848-
\tcode{std::inplace_stop_callback}\iref{stopcallback.cons,stopcallback.inplace.cons}
849-
when a callback invocation exits via an exception, or
850-
851-
\item%
852-
when a \tcode{run_loop} object is destroyed
853-
that is still in the \tcode{running} state\iref{exec.run.loop}, or
854-
855-
\item%
856-
when \tcode{unhandled_stopped} is called on
857-
a \tcode{with_awaitable_senders<T>} object\iref{exec.with.awaitable.senders}
858-
whose continuation is not a handle to a coroutine
859-
whose promise type has an \tcode{unhandled_stopped} member function.
860-
861-
\end{itemize}
862-
863-
\end{note}
864-
865-
\pnum
866-
\indextext{\idxcode{terminate}}%
867-
In the situation where no matching handler is found, it is
868-
\impldef{stack unwinding before invocation of \tcode{std::terminate}}
869-
whether or not the stack is unwound
870-
before \tcode{std::terminate} is invoked.
871-
In the situation where the search for a handler\iref{except.handle} encounters the
872-
outermost block of a function
873-
with a non-throwing exception specification\iref{except.spec}, it is
874-
\impldef{whether stack is unwound before invoking the function \tcode{std::terminate}
875-
when a \tcode{noexcept} specification is violated}
876-
whether the stack is unwound, unwound partially, or not unwound at all
877-
before the function \tcode{std::terminate} is invoked.
878-
In all other situations, the stack shall not be unwound before
879-
the function \tcode{std::terminate}
880-
is invoked.
881-
An implementation is not permitted to finish stack unwinding
882-
prematurely based on a determination that the unwind process
883-
will eventually cause an invocation of the function
884-
\tcode{std::terminate}.
885750
\indextext{exception handling|)}

source/xrefdelta.tex

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,10 @@
7373
\removedxref{type.index.members}
7474
\removedxref{type.index.hash}
7575

76+
% Dissolving [except]
77+
\removedxref{except.special}
78+
\removedxref{except.special.general}
79+
7680
%%% Renamed sections.
7781
%%% Examples:
7882
%
@@ -98,6 +102,7 @@
98102
% https://github.com/cplusplus/draft/pull/7276
99103
\movedxref{except.uncaught}{except.throw}
100104

105+
101106
%%% Deprecated features.
102107
%%% Example:
103108
%

0 commit comments

Comments
 (0)