------- Comment #5 from xinliangli at gmail dot com 2008-06-04 04:15 ------- (In reply to comment #4) > This would not be legal, there is no reason operator new can't return a > pointer > that already exists in the program. >
This is certainly a flaw in the C++ standard (it requires p returned from operator new to be different from previous calls to the operator unless the previous call's return is passed to operator delete -- but it does not require the pointer returned to be not pointing to any known location) -- and I do not see a reason this is intentional. For compiler optimization, it would better to assume the aggressive default, and provide an option to turn it off in case user provided definition violates the aliasing assumption. Someone in the language committee might need to bring this up. David -- http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23383