Valid But Unspecified

std::string a = "long enough that this string is definitely heap allocated";
std::string b = std::move(a);

a += "!";
std::cout << a.size() << " " << a.front() << "\n";

Which statement is guaranteed by the standard?

A

a += "!" is legal, but a.size() is undefined behaviour because it reads unspecified state.

B

The whole program is undefined behaviour: after a move, the only legal operation on a is destruction.

C

a += "!" is legal because assignment has no precondition on the current value, but nothing fixes what a.size() prints, because the moved-from value is valid and unspecified.

D

a is guaranteed empty after the move, so the program always prints 1 !.