According to the Standard, copying the pointer q = p;
, is undefined behaviour.
Reading J.2 Undefined behaviour states:
The value of a pointer to an object whose lifetime has ended is used (6.2.4).
Going to that chapter we see that:
6.2.4 Storage durations of objects
The lifetime of an object is the portion of program execution during which storage is
guaranteed to be reserved for it. An object exists, has a constant address,33)and retains
its last-stored value throughout its lifetime.34)If an object is referred to outside of its
lifetime, the behavior is undefined. The value of a pointer becomes indeterminate when
the object it points to (or just past) reaches the end of its lifetime.
What is indeterminate:
3.19.2 indeterminate value:
either an unspecified value or a trap representation
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…