Given the following code, is proposition 2 equivalent to proposition 4? I can't define "equivalent" precisely though.
int main() {
// Keep your mind of of (void) its just here to remove unused expression
// result warnings
using T = int;
using U = char;
using V = unsigned long;
// Proposition 1
// As far as I know, only cstyle and reinterpret_cast can to that
(void)reinterpret_cast<V>(nullptr);
(void)(V)(nullptr);
// Proposition 2
// This snipet wont compile, as expected
// (void)static_cast<V>(nullptr);
// Proposition
// Casting U* to T* using reinterpret_cast OK
(void)reinterpret_cast<T *>(static_cast<U *>(nullptr));
// Proposition 3
// Casting U* to T* using static_cast, wont compile as expected
// (void)static_cast<T *>(static_cast<U *>(nullptr));
// Proposition 4
// Casting U* to void* is always OK, then casting from void* to T* is always
// possible using static_cast
(void)static_cast<T *>(static_cast<void *>(static_cast<U *>(nullptr)));
}
The code is also available here: https://godbolt.org/z/1xbvsWrhz