Why is this an issue?
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
}
}
}