42 lines
686 B
Plaintext
42 lines
686 B
Plaintext
The attribute ``++noreturn++`` indicates that a function does not return.
|
||
|
||
Using this attribute allows the compiler to do some assumptions that can lead to optimizations. However, if a function with this attribute ever returns, the behavior becomes undefined.
|
||
|
||
|
||
== Noncompliant Code Example
|
||
|
||
----
|
||
[[noreturn]] void f () {
|
||
while (1) {
|
||
// ...
|
||
if (/* something*/) {
|
||
return; // Noncompliant, this function should not return
|
||
}
|
||
}
|
||
}
|
||
----
|
||
|
||
|
||
== Compliant Solution
|
||
|
||
----
|
||
[[noreturn]] void f() { // Compliant
|
||
while (true) {
|
||
// ...
|
||
}
|
||
}
|
||
----
|
||
Or
|
||
|
||
----
|
||
void f() {
|
||
while (true) {
|
||
// ...
|
||
if (/* something*/) {
|
||
return; // Compliant
|
||
}
|
||
}
|
||
}
|
||
----
|
||
|