Rvalue references and Exceptions


Move constructors must not throw.




David Abrahams: "Implicit move must go"
http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2010/n3153.htm

Problems with implicit generated move constructors and assignment operators.


#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>

struct X
{
    // invariant: v.size() == 5
    X() : v(5) {}

    ~X()
    {
        std::cout << v[0] << std::endl;
    }

 private:
    std::vector<int> v;
};

int main()
{
    std::vector<X> y;
    y.push_back(X()); // X() rvalue: copied in C++03, moved in C++0x
}