Re:Catch-23: The New C Standard Sets the World on Fire
by Asooka on Sunday April 02, 2023 @06:25AM
(#35409066)
This just shows that "unreachable" is almost impossible to use safely. The only safe use of unreachable is if it is immediately after an instruction that makes the program stop running. It is not for "this cannot happen", because things that "cannot happen" happen all the time. If you use "unreachable", you're just asking for trouble and it seems the compiler authors are happy to oblige.
[ Parent
| on HN ]
Re:Catch-23: The New C Standard Sets the World on Fire
by josephcsible on Sunday April 02, 2023 @12:37PM
(#35412384)
This couldn't be more wrong. What you say to never use unreachable for is one of the most important use cases of unreachable. The whole point is to give the optimizer an assumption that it can't figure out on its own.
Re:Catch-23: The New C Standard Sets the World on Fire
by lldb on Sunday April 02, 2023 @07:03PM
(#35416258)
One example of it being useful is unchecked std::variant access in c++ - there isn’t any api to access it like a union (if you already know the type) but you can mark the wrong type path unreachable to the same effect.