I just found an error in my code due to using an std::vector after having moved it. The code was something like :
std::vector<SomeObject> v1;
//fill v1;
this->v2=std::move(v1);
for(unsigned int i=0; i<v1.size(); i++)
{
//the code in the for loop was not executed
}
The behavior is not surprising (the state of v1 is undefined, as long as it is valid; so an empty vector seems a logical choice).
My question is : is it possible to make g++ give me a warning when using a variable after moving it? If so, what flag should I add?
NB : I suppose it is not possible to guarantee the detection of such warning (it would, I think, be equivalent to the halting problem, that can't be solved for the general case). But it would already be very useful if I get a warning either for simple cases like the example (use after move can be proven), or if I get a warning when g++ can't prove that it is safe.
Thanks a lot in advance