if (Foo* f = GetPtr(); f->HasValue()) {} // wrong; f can be null
if (Foo* f = GetPtr(); f && f->HasValue()){}
if (Foo* f = GetPtr()) { f->DoTheThing(); // this is perfectly safe. }