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 31,641 of 33,346   
   =?windows-1252?Q?Daniel_Kr=FCgler?= to All   
   Re: Reference to show that if (this == N   
   08 Nov 11 00:05:06   
   
   From: daniel.kruegler@googlemail.com   
      
   Am 07.11.2011 21:02, schrieb Carlos Moreno:   
   > Clarification up-front: I'm not after a discussion or to explain   
   > to me how or why this works or doesn't work. What I'm really   
   > after is a *specific* reference to a section on the standard, or   
   > maybe on a book like TC++PL, that *very explicitly* says   
   > something about the issue.   
   >   
   > So, the issue: I'm trying to convince a colleague of mine that   
   > using recursion in a tree structure, and allowing it to step outside   
   > the tree by calling the method on the NULL pointers is not legal   
   > (as in, it invokes undefined behaviour).   
      
   Since this question has repeatedly asked for and answered in diverse   
   newsgroups I can only assume that this colleague has already found his   
   opinion and any further discussion won't change anything. There is a   
   simple logical error in the example code given to "prove" that checking   
   for a NULL 'this' value inside a member function would prevent UB,   
   simply because once the underlying assumption is that the UB could   
   happen between the member function call (with a NULL object pointer) and   
   the point within the function body. This is like arguing that it is OK   
   to cross the border of a foreign country without any extra permission to   
   do so, because *once* you are one the ground of your embassy within that   
   country, you are effectively on the ground of your own country, q.e.d.   
      
   Pictorial arguments aside, 5.2.2 [expr.call] p4 says:   
      
   "4 When a function is called, each parameter (8.3.5) shall be   
   initialized (8.5, 12.8, 12.1) with its corresponding argument. [ Note:   
   Such initializations are indeterminately sequenced with respect to each   
   other (1.9) — end note ] If the function is a non-static member   
   function, the this parameter of the function (9.3.2) shall be   
   initialized with a pointer to the object of the call, converted as if by   
   an explicit type conversion (5.4)."   
      
   If you use a null pointer, this does not satisfy "initialized with a   
   pointer to the object of the call" because there would be no object   
   involved.   
      
   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