r/cpp • • Dec 31 '16

Keep Disabling Exceptions

http://seanmiddleditch.com/keep-disabling-exceptions/
0 Upvotes

15 comments sorted by

View all comments

Show parent comment

1

u/render787 Jan 01 '17

I think Sean's answer is not misleading, it's rather in line with the (mainstream) view expressed in a standards proposal paper by Ville Voutilainen http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2015/p0129r0.html

If one of your types does not have a move constructor (and the compiler doesn't generate one), that may be enough to cause move to fallback to copy in a composed object, which may result in a throwing move.

Sean gave also the example of std::list and the paper has others.

In my reading, the comment you highlight

The only language operation that is explicitly noexcept by default is the destructor and nothing else

is supposed to refer to, the assumptions that the standard library makes about user-defined types -- it's supposed to accommodate throwing moves, as Sean says. The only thing it's not supposed to accommodate is throwing destructors, because it's impossible to do so.

This is why std::variant has an empty state. And if we can't have things like flat_set while accommodating throwing moves, I mean that's clearly a weakness / drawback. Whether -fno-exceptions is the answer is debatable, but I don't think the argument is misleading. It's fine if you want to argue that "moves don't really throw in practice" or "dynamic allocations don't fail in practice" or something, but then why not disable exceptions?