The latest version of the standard states, after explaining that
delete calls destructors and deallocation functions (which may themselves change the data, depending on how you wrote them, although for primitive types such as in the example code here, the values are not changed)
If the argument given to a deallocation function in the standard library is a pointer that is not the null pointer value (4.10), the deallocation function shall deallocate the storage referenced by the pointer, rendering invalid all pointers referring to any part of the deallocated storage. The effect of using an invalid pointer value (including passing it to a deallocation function) is undefined. |
Anything could happen if you tried to access that memory; as kbw says, to access that memory is erroneous, and if you do so, you're asking for trouble.
To make a pointer, and give that pointer a value, and that value happens to be the address unallocated memory, is not an error. You can give a pointer any value you like (i.e. you can make it point at any memory location you want to). It's only a problem if you then try to access the memory that pointer is pointing to.
Which version of g++? I'm using 4.7.0
Ideone's g++ 4.3.4 is also happy with it:
http://ideone.com/IPUgO
Edit: Reading back, I could have been clearer here.
This:
otherList = &list[1];
involves an attempt to use list to access some deallocated storage (i.e. list[1], which is bad, but
otherList = list;
is not an attempt to access deallocated storage.