MkCastTo: Use static_cast instead of reinterpret_cast

If the type is convertible to the other one, then a static_cast will be
able to perform the conversion (assuming the type itself is
constructible). If it isn't, then nullptr will just be converted to a
null version of T*.
This commit is contained in:
Lioncash 2019-09-30 22:22:09 -04:00
parent bf65456a2c
commit 91bdfa86f6
1 changed files with 1 additions and 1 deletions

View File

@ -184,7 +184,7 @@ for tp in CENTITY_TYPES:
sourcef.write('''template <class T> sourcef.write('''template <class T>
void TCastToPtr<T>::Visit(%s* p) { void TCastToPtr<T>::Visit(%s* p) {
static_assert(sizeof(T) > 0 && !std::is_void_v<T>, "TCastToPtr can not cast to incomplete type"); static_assert(sizeof(T) > 0 && !std::is_void_v<T>, "TCastToPtr can not cast to incomplete type");
ptr = reinterpret_cast<T*>(std::is_convertible_v<%s*, T*> ? p : nullptr); ptr = static_cast<T*>(std::is_convertible_v<%s*, T*> ? p : nullptr);
} }
''' % (qual, qual)) ''' % (qual, qual))