I am aware that adding const can be dangerous for lower level pointees of a pointer.
Are there any cases where it could be dangerous to add const
to the topmost pointee of a pointer?
Concretely, are there any two (possibly cv-qualified) types T
and U
, such that
T *pointer = ...;
U *target = static_cast<U *>(pointer);
is well defined and safe but
T *pointer = ...;
U const *target = static_cast<U const *>(pointer);
is not?