Seemingly the confusion is due to the multiple meanings of the word "return" here? One can visualize the annotation as [[aborts]] or [[terminates]], rather than "doesn't return".
This is also why there's very little point to introspecting the presence of this annotation or even overloading based on this annotation.
Discussing whether a function which always terminates "returns" or "not-returns" an int is as useful as discussing whether a function which is never executed returns an int. The semantic analysis is rather clear in both cases.
FreePascal has the same issue with the warning in divide2 and it also has a noreturn attribute. So can you be tempted to add the attribute and it get rids of the warning. But it is wrong.
In FreePascal noreturn means that the function does not return, i.e. the execution does not leave the scope. An exception would leave the function, so it is not allowed.
Noreturn functions can only have an infinite loop or kill the process
Nice post, but I believe that function g (with the infinite loop) is UB in C++, as it’s required that infinite loops that never break must have side-effects.
7 comments
[ 2.2 ms ] story [ 28.4 ms ] threadThis is also why there's very little point to introspecting the presence of this annotation or even overloading based on this annotation.
Discussing whether a function which always terminates "returns" or "not-returns" an int is as useful as discussing whether a function which is never executed returns an int. The semantic analysis is rather clear in both cases.
FreePascal has the same issue with the warning in divide2 and it also has a noreturn attribute. So can you be tempted to add the attribute and it get rids of the warning. But it is wrong.
In FreePascal noreturn means that the function does not return, i.e. the execution does not leave the scope. An exception would leave the function, so it is not allowed.
Noreturn functions can only have an infinite loop or kill the process
https://doc.rust-lang.org/std/primitive.never.html
There is no way where you can say: this function returns a string and is no-return.