The following function compiles
struct Base {};
struct Derived : Base {};
std::unique_ptr<const Base> f() {
  std::unique_ptr<Derived> p(new Derived);
  return p;
}
Based on this answer, return expression can be considered as rvalue for overload resolution if it is eligible for copy elision. And based on this, a non-volatile object with automatic storage duration is eligible for copy elision if it is the same type as returning type, which is not the case here.
Do I miss anything? Can anyone point out the sections in standard that allows the above code?
Aucun commentaire:
Enregistrer un commentaire