News for hackers. Stuff that matters.
Re:Three new utility functions in C++23 by fluoridation on Wednesday November 09, 2022 @08:18AM (#33531151)
The point is that you're telling the compiler "I don't care what happens if control reaches here. Assume it never will and use that information to better optimize the rest". It's not an alternative to abort() or throwing because the compiler still needs to generate code for them.
Re:Three new utility functions in C++23 by DougBTX on Wednesday November 09, 2022 @01:42PM (#33536011)
Yes, that’s what I mean, the compiler can completely remove a branch which is unreachable, along with any checks. If it was forced to keep the checks and report an error instead, any bug would be more obvious. If the compiler removes checks for bugs, then the application could silently continue, obscuring the bug.

So this is a “hide bugs but maybe improve performance” function.

Re:Three new utility functions in C++23 by fluoridation on Wednesday November 09, 2022 @03:28PM (#33537379)
No, it doesn't hide bugs. It has no defined effect on the obviousness of bugs. The reason is that modern compilers are pretty much theorem solvers, and they're able to propagate truth values in order to deduce facts about programs. For example, a compiler could deduce that since a branch is never reached, a particular pointer is never null, and could therefore skip a null check that it deduced was redundant that would have prevented a null dereference. If it turns out that the branch is reachable and the pointer is null, the pointer would be dereferenced and the program would crash immediately (typically). But UB is UB; once you hit it all behaviors are permissible, from immediate crash, to silent data corruption, to nasal demons.