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,259 of 33,346   
   Andy Lutomirski to nroberts   
   Re: Placement new myself   
   08 May 12 11:31:05   
   
   4ffa570d   
   From: luto@amacapital.net   
      
   On 05/07/2012 07:41 PM, nroberts wrote:   
   > Someone asked a question with some really deranged code and I'm unable   
   > to find something in the standard that would indicate whether this   
   > would be defined or not:   
   >   
   > struct foo; // let's talk the generic case here.  If there are   
   > specifics please explain   
   >   
   > foo f = foo();   
   >   
   > new (&f) foo(f);   
   >   
   > As I understand it, this will try to recreate f on top of itself with   
   > itself.   
   >   
   > My instinct says that this is likely undefined and in some cases is   
   > going to do absolutely absurd stuff...   
   >   
   >   
      
   It looks rather similar to this:   
      
   #include    
      
   int main()   
   {   
      std::string x(x);   
      return 0;   
   }   
      
   gcc and clang will cheerfully compile this without warnings, but it   
   (unsurprisingly) crashes at runtime.   
      
   Yes, I typed something like this by accident once while refactoring.   
      
   --Andy   
      
      
   --   
         [ 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