home bbs files messages ]

Forums before death by AOL, social media and spammers... "We can't have nice things"

   comp.lang.c++.moderated      Moderated discussion of C++ superhackery      33,346 messages   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]

   Message 32,274 of 33,346   
   =?ISO-8859-1?Q?Daniel_Kr=FCgler?= to All   
   Re: Trivial initialization after non-tri   
   10 May 12 14:30:06   
   
   e6174bcb   
   From: daniel.kruegler@googlemail.com   
      
   Am 10.05.2012 20:48, schrieb Nikolay Ivchenkov:   
   > Consider the following example:   
   >   
   >     struct X   
   >     {   
   >         ~X() {}   
   >     };   
   >   
   >     template   
   >         void destroy(T&x)   
   >             { x.~T(); }   
   >   
   >     int main()   
   >     {   
   >         X *p = (X *)operator new(sizeof(X));   
   >         destroy(*p);   
   >         destroy(*p); // well-defined or undefined?   
   >         operator delete(p);   
   >     }   
   >   
   > According to C++11 - 3.8/1, non-trivial destruction ends the life-time   
   > of an object. Can we assume that a new object of the same type exists   
   > at the same location immediately after such non-trivial destruction   
   > has done if its initialization is trivial?   
      
   I find the current wording state hard to interpret, but if we consider   
   the current wording state of   
      
   http://www.open-std.org/jtc1/sc22/wg21/docs/cwg_active.html#1116   
      
   as representing the committees intention I would say that without   
   intervening copy of another X object into the storage pointed to by   
   pointer p, the life-time of the object has not started again, therefore   
   the second destruction would invoke undefined behaviour. But this also   
   would mean that the first destruction was invalid, because not object   
   representation of any X object had ever been copied into the originally   
   allocated memory.   
      
   HTH & Greetings from Bremen,   
      
   Daniel Krügler   
      
      
   --   
         [ See http://www.gotw.ca/resources/clcm.htm for info about ]   
         [ comp.lang.c++.moderated.    First time posters: Do this! ]   
      
   --- SoupGate-Win32 v1.05   
    * Origin: you cannot sedate... all the things you hate (1:229/2)   

[   << oldest   |   < older   |   list   |   newer >   |   newest >>   ]


(c) 1994,  bbs@darkrealms.ca