Create shared_ptr in else block