Hey folks, I recently hit a
compile error on ios/android for code that looked like
class A {};
class B : public A {};
// Fails to compile on ios and android (ios-device-xcode-clang, ios-simulator-xcode-clang, linux_android_rel_ng, android_n5x_swarming_rel, android_compile_dbg, android_arm64_dbg_recipie)
std::unique_ptr<A> Foo() {
auto b = base::MakeUnique<B>();
<do something that requires having a B object>
return b;
}
My question is, what do you think is a better work around?
> return std::move(b);
or
> return base::WrapUnique<A>(b.release());
In the past I've seen compiler errors when I return std::move(local_variable) because it's blocking copy elision, but I don't understand copy elision well enough to know if it's allowed at all in this scenario. But the latter seems kind of clunky, I guess you could view it as showing explicit intent instead.
Any opinions?