samedi 29 août 2015

use-after-move POD parts of composite class with defaulted move ctor

Suppose we have a class with non-POD and POD parts. Move constructor and move assignments are defaulted. Are the POD-parts of an instance of this class safe to use after a move?

#include <string>
struct A {
    std::string s = "foo";
    int i = 42;
};
A a;
A b = std::move(a);
int j = a.i; //OK or UB?

Is element-wise move/copy guaranteed (so this would be OK) or could a conforming implementation alter the POD parts (e.g., by swapping with a default-constructed object)?

Aucun commentaire:

Enregistrer un commentaire