I try to deallocate a class(*) pointer which points to an object of another type.
I know the difference between declared type and dynamic type. I should not be able to access any variable in the object with a class(*) pointer. So I was expecting an error when deallocating the object with class(*) pointer. However it works fine. Valgrind also shows no memory leak.
I am curious why. Does this mean "deallocate" implicitly detect the dynamic type? Any explanation would be appreciated.
class(*), pointer :: ptr => NULL()
class(point), pointer :: ptr_pnt => NULL() ! point is a derived data type
allocate( ptr_pnt )
... ! set the data in ptr_pnt
ptr => ptr_pnt
deallocate( ptr )
nullify( ptr_pnt )