why () is () and [] is [] work in other way?

Evan Driscoll driscoll at cs.wisc.edu
Thu Apr 26 12:05:16 EDT 2012


This thread has already beaten a dead horse enough that the horse came 
back as a zombie and was re-killed, but I couldn't help but respond to 
this part:


On 01/-10/-28163 01:59 PM, Adam Skutt wrote:
> Code that relies on the identity of a temporary object is generally
> incorrect.  This is why C++ explicitly forbids taking the address
> (identity) of temporaries.

Except that C++ *doesn't* really forbid taking the address of a 
temporary, at least indirectly:

     #include <iostream>

     int const * address_of(int const & x) {
         return &x;
     }

     int main() {
         std::cout << address_of(1+2) << "\n";
     }

That complies without warning with GCC 4.6 '-Wall -Wextra', MSVC 2010 
'/W4', and Comeau's online front end, and I am pretty confident that the 
above code is perfectly legal in terms of provoking undefined behavior 
(in the technical C++ sense of "your program is now allowed to set your 
cat on fire").

Evan



More information about the Python-list mailing list