Is it possible to add a compiler warning when calling methods on objects that have been moved. Especially in a function call? I've been bitten by this a few times now.
Throws SIGSEGV:
std::unique_ptr<Thingy> smart_ptr = ...;
...
delegate_->Resolve(
smart_ptr->bar(),
base::Bind(&Handler::OnResolveHandled,
weak_factory_.GetWeakPtr(), base::Passed(&smart_ptr)));
FIXED:
std::unique_ptr<Thingy> smart_ptr = ...;
...
const Bar& ref = smart_ptr->bar();
delegate_->Resolve(
ref,
base::Bind(&Handler::OnResolveHandled,
weak_factory_.GetWeakPtr(), base::Passed(&smart_ptr)));
The cause of this is that there's no required ordering for the evaluation of function parameters. So, smart_ptr is moved before smart_ptr->bar() is evaluated. So, smart_ptr->bar() might cause a segfault.