rspec/rules/S5267/rule.adoc
2021-02-02 16:54:43 +01:00

42 lines
686 B
Plaintext
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

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
}
}
}
----