[dcl.attr.noreturn] (original) (raw)
9 Declarations [dcl]
9.13 Attributes [dcl.attr]
9.13.10 Noreturn attribute [dcl.attr.noreturn]
The attribute-token noreturn specifies that a function does not return.
The attribute may be applied to a function or a lambda call operator.
The first declaration of a function shall specify the noreturn attribute if any declaration of that function specifies thenoreturn attribute.
If a function is declared with the noreturn attribute in one translation unit and the same function is declared without the noreturn attribute in another translation unit, the program is ill-formed, no diagnostic required.
If a function f is invoked where f was previously declared with the noreturnattribute and that invocation eventually returns, the behavior is runtime-undefined.
[Note 1:
The function can terminate by throwing an exception.
— _end note_]
Recommended practice: Implementations should issue a warning if a function marked [[noreturn]] might return.
The value of a has-attribute-expression for the noreturn attribute should be 0 unless the implementation can issue such warnings.
[Example 1: [[ noreturn ]] void f() { throw "error"; } [[ noreturn ]] void q(int i) { if (i > 0) throw "positive";} — _end example_]