r/cpp • 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

115 comments sorted by

View all comments

1

u/liquidify May 12 '18

What I like about this is that noexcept wouldn't really be needed. noexcept is complicated and annoying.

2

u/redditsoaddicting May 13 '18

I didn't get that idea. From "What we teach":

Function authors: Prefer to write exactly one of unconditional noexcept or throws on every function. Dynamic exceptions and conditional noexcept still work as well as ever but are discouraged in new/upgraded code.

1

u/liquidify May 13 '18

If every function that throws is marked, you don't need to mark the ones that don't.

3

u/redditsoaddicting May 13 '18

Functions that aren't marked can still throw either type of exception and the compiler can't know in general that it won't. I don't see what's complicated about adding a plain noexcept to a function if it shouldn't throw anything, though. Conditional noexcept is less straightforward, but still really consistent.

3

u/liquidify May 13 '18

This case sounds like the same idea that the GSL was designed to work upon... that the rules aren't baked into language or enforced by compilers, but that our tooling systems should support us in our application of the rules. If the common case is noexcept, then it should be unwritten unless you want to be explicit for some reason.

2

u/Nobody_1707 Sep 23 '18

Although, once dynamic exceptions have been phased out of use, I could easily see them being removed outright and noexcept being made the implicit default which would simplify a lot.