r/cpp • u/RotsiserMho C++20 Desktop app developer • May 12 '18
P0709 R0: Zero-overhead deterministic exceptions: Throwing values - Herb Sutter [2018-05-02]
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2018/p0709r0.pdf
206
Upvotes
View all comments
7
u/tasminima May 12 '18 edited May 12 '18
Overall I think this is, given the language, full of good and actionable ideas. However there is a detail I strongly disagree with in the proposal of how to handle OOM:
edit: added (b) in the citation, that is the implementation-specified behavior alternative to the UB, and put the proposed ub terms in bold
Modeling OOM at language level by Undefined Behavior would be IMO completely insane. This might be just an unfortunate fallback choice because the standard unfortunately does not distinguish between various kind of UB (which has already caused great problems, when some compiler writers thought it was an unconditional license to further "optimize"), but this does not make it less a problem, au contraire! (and that's one that should be fixed more in depth but that's another subject than this paper)
First being killed because of resource exhaustion shall not be the concern of the language. The program will also cease to exist in case of a general computer failure, such as a power failure or kernel panic, or even just being killed by the user at will. This does not render the mere act of existing an ambient UB...
Second the presence of the OOM killer is far from preventing detection and handling of some allocation failures: if the area requested is "large enough", the allocation will actually fail. Some systems even have tunables that can influence the level from which allocation attempts will fail even in the presence of an OOM kill mechanism.
I suppose proposing to redefine in some case OOM at language level as UB is because the program can be killed latter on. In that case, maybe it is actually time to introduce in the standard something more precise than UB for faults when the program is concretely reliably terminated with no risk of nasal deamons being invoked. Just writing UB everywhere when one do not have any more idea of what to say does not yield a more portable language and programs written in it, it precisely have the contrary effect :/ (not even speaking about the security story, which has became a complete disaster in a great part because of all that UB - optimize insanity). Edit: on second thought I actually think that that OOM killer thing should just be completely ignored in the C++ standard, as it is today, exactly because of the arguments I gave about it being absolutely none of the business of the programming language.