Are move constructors required to be noexcept?

Here's to shed some further light on this.

It seems that std::vector in particular is picky about whether or not you declare your move constructors with noexcept. If you do, then std::vector will use them. If you don't then std::vector will resort to using your copy constructor instead. At least in some cases. Notably whenever it reshuffles items internally, after an internal array resize.

You can see the effects in this example, where noexcept is not declared:

http://coliru.stacked-crooked.com/a/285cd07a9a52da3b

And in this example, where it is:

http://coliru.stacked-crooked.com/a/d043774ec4c279ec

In the first example, std::vector uses the copy constructor already at the second and third insertion with push_back. In the second example, it does the same operation, but with the move constructor instead.


Are move constructors in general allowed to throw? Yes. Should they? No.

In general, nothing you do within them should be anything that could throw. You shouldn't be allocating memory, calling other code, or anything like that. The only reason to write a move constructor is to abscond with someone else's memory pointers and object references. You should be copying a few basic types and nulling out the values in the other object. Those things shouldn't throw.

So while it is allowed, it's not a good idea. If you're doing it, rethink what you're doing in your move operations.