Indicates that the function does not return.
[edit] Syntax [edit] ExplanationIndicates that the function will not return control flow to the calling function after it finishes (e.g. functions that terminate the application, throw exceptions, loop indefinitely, etc.). This attribute applies to the name of the function being declared in function declarations only.
If a function previously declared with [[noreturn]] is invoked and that invocation eventually returns, the behavior is runtime-undefined.
The first declaration of the function must specify this attribute if any declaration specifies it. If a function is declared with [[noreturn]] in one translation unit, and the same function is declared without [[noreturn]] in another translation unit, the program is ill-formed; no diagnostic required.
[edit] Example[[noreturn]] void f() { throw "error"; // OK } void q [[noreturn]] (int i) { // behavior is undefined if called with an argument <= 0 if (i > 0) throw "positive"; } // void h() [[noreturn]]; // error: attribute applied to function type of h, not h itself int main() { try { f(); } catch(...) {} try { q(42); } catch(...) {} }[edit] Standard library
The following standard functions are declared with noreturn
attribute:
(deprecated in C++11)(removed in C++17)
function called when dynamic exception specification is violatedstd::nested_exception
) throws its argument with std::nested_exception mixed in
The following behavior-changing defect reports were applied retroactively to previously published C++ standards.
DR Applied to Behavior as published Correct behavior CWG 2924 C++11 returning from a [[noreturn]] functionRetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4