Legality of using operator delete on a pointer obtained from placement new

后端 未结 4 1210
时光说笑
时光说笑 2020-12-01 15:19

I\'m dang certain that this code ought to be illegal, as it clearly won\'t work, but it seems to be allowed by the C++0x FCD.

class X { /* ... */};
void* raw         


        
4条回答
  •  鱼传尺愫
    2020-12-01 15:25

    I found this in the library section of the standard, which is about as counter-intuitive a location (IMO) as possible:

    C++0x FCD (and n3225 draft) section 18.6.1.3, [new.delete.placement]:

    These functions are reserved, a C ++ program may not define functions that displace the versions in the Standard C ++ library (17.6.3). The provisions of (3.7.4) do not apply to these reserved placement forms of operator new and operator delete.

    void*  operator  new(std::size_t  size,  void*  ptr)  throw();
    void*  operator  new[](std::size_t  size,  void*  ptr)  throw();
    void  operator  delete(void*  ptr,  void*)  throw();
    void  operator  delete[](void*  ptr,  void*)  throw();
    

    Still, the section defining legal expressions to pass to delete is 5.3.5, not 3.7.4.

提交回复
热议问题