3

If the parameter type is non-trivial for the purposes of calls, the caller must allocate space for a temporary and pass that temporary by reference

https://itanium-cxx-abi.github.io/cxx-abi/abi.html#value-parameter

And *non-trivial for the purpose of calls is defined as:

  • it has a non-trivial copy constructor, move constructor, or destructor
  • all of its copy and move constructors are deleted.

https://itanium-cxx-abi.github.io/cxx-abi/abi.html#non-trivial

Is there any explicit reason for this?

lz96
  • 2,816
  • 2
  • 28
  • 46
  • This is the normal non-register pass-by-value mechanism. (Pass by value is the same as making a copy and passing the copy by reference). Types which ARE trivial for the purpose of calls may be passed in registers – M.M Nov 16 '18 at 04:01
  • @M.M What I'm confused about is that, why types that could perfectly fit in register (e.g., std::unique_ptr) needs to be passed by reference because it has a non-trivial destructor? Is this behavior implied by the spec that caller invokes ctor/dtor of arguments? If so, why not allow the callee to destroy argument when passed by value? This enforcement makes it impossible to eliminate `unique_ptr` destroy check when called by value (See https://stackoverflow.com/questions/53330428/why-this-dead-store-of-unique-ptr-cannot-be-eliminated) – lz96 Nov 16 '18 at 04:57

0 Answers0