rspec/rules/S5267/rule.adoc

41 lines
685 B
Plaintext
Raw Normal View History

2021-01-27 13:42:22 +01:00
The attribute ``++noreturn++`` indicates that a function does not return.
2020-06-30 12:50:28 +02:00
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
2020-06-30 12:50:28 +02:00
----
void f() {
while (true) {
// ...
if (/* something*/) {
return; // Compliant
}
}
}
----