Is the following code UB?
int i = 5;
void *p = &i;
int* &r = reinterpret_cast<int* &>(p);
int* p2 = r;
Please note I do not dereference pointer.
In this absolutely specific case without deferencing it should be okay I think. I verified pointer value. It's different story when sizeof(void*) and sizeof(int*) are different (although I do not know whether that is even possible).
By doing this, you are taking complete responsibility of very known scenario.
int i = 5;
void *p = &i; //convert int* => void*
int* &r = reinterpret_cast<int* &>(p); //convert void* which was int* to int*&
int* p2 = r; //**copy** address stays same
void*member. In derived classes I need to cast this member to reference to specific pointer. I can't cast pointer by value because this. I need exactly reference.