Return value of placement new

后端 未结 2 428
挽巷
挽巷 2021-02-05 03:11

Consider the following C++14 code:

#include 
#include 
#include 

struct NonStandardLayout
{
    // ...
};

int main         


        
2条回答
  •  误落风尘
    2021-02-05 03:45

    18.6.1.3 Placement forms [new.delete.placement]

    void* operator new(std::size_t size, void* ptr) noexcept;

    Returns: ptr.

    It is unambiguously specified that the placement new operator returns whatever pointer is passed to it. "Returns: ptr". Can't get any clearer than that.

    That, pretty much, seals the deal for me as far as "the return value from placement new" goes: placement new does nothing to the pointer it places, and it always returns the same pointer.

    Everything else in your question relates to any other changes that might occur as the result of the other casts; but you're asking specifically about the return value from placement new, so I take it that you're accepting that all other conversion are type-conversions only, and have no effect on the actual pointer, and you were only asking about placement new -- but it would also be possible to go through the other casts, and make a similar determination.

提交回复
热议问题