Namespaces
Variants
Views
Actions

Difference between revisions of "cpp/language/attributes/noreturn"

From cppreference.com
< cpp‎ | language‎ | attributes
(add navbar)
m (use template)
Line 1: Line 1:
{{title | {{small|C++ attributes:}} noreturn}}
+
{{cpp/attribute/title|noreturn}}
 
{{cpp/attribute/navbar}}
 
{{cpp/attribute/navbar}}
  

Revision as of 03:36, 24 June 2018

Template:cpp/attribute/title Template:cpp/attribute/navbar

Indicates that the function does not return.

Syntax

[[noreturn]] function-declaration (1)
specifiers function-name [[noreturn]] parameters-and-qualifiers (2)

Explanation

Indicates that the function does not return.

This attribute applies to function declarations only. The behavior is undefined if the function with this attribute actually returns.

The following standard functions have this attribute: std::_Exit, std::abort, std::exit, std::quick_exit, std::longjmp(since C++17), std::unexpected, std::terminate, std::rethrow_exception, std::throw_with_nested, std::nested_exception::rethrow_nested.

Example

[[ noreturn ]] void f() {
  throw "error";
  // OK
}
 
[[ noreturn ]] void q(int i) {
  // behavior is undefined if called with an argument <= 0
  if (i > 0) {
    throw "positive";
  }
}