Is there a compiler attributes (clang / gcc) that does something like noreturn
but for loop?
Something like:
__atribute__((loopsnoreturn)) for (int i=0; i<12; i++)
{
if(i==5) return 0; //< Compiler error
}
If the loop can only exit via return
, then the loop condition i<12
must be redundant and you can simplify it to just 1
. That should be enough for the compiler to realize that code after the loop is unreachable and have the optimization effects that you seem to expect.
Otherwise, you can also use __builtin_unreachable();
after the loop in order to the tell the compiler that the path after the loop can't be reached.
for (int i=0; i<12; <i++)
. I'd just fix it, but not sure I understand the question enough to be confident.