core: assert that Ptr is not null on dereference

This way it is possible to catch errors even if the pointer is not actually dereferenced,
for example when it is used to call an object method or stored as a reference.
This commit is contained in:
Alexander Krotov
2019-11-11 19:48:15 +03:00
parent c312a9f4b3
commit 149f748cf9

View File

@@ -780,6 +780,7 @@ template <typename T>
T *
Ptr<T>::operator -> ()
{
NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer");
return m_ptr;
}
@@ -787,6 +788,7 @@ template <typename T>
T *
Ptr<T>::operator -> () const
{
NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer");
return m_ptr;
}
@@ -794,6 +796,7 @@ template <typename T>
T &
Ptr<T>::operator * () const
{
NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer");
return *m_ptr;
}
@@ -801,6 +804,7 @@ template <typename T>
T &
Ptr<T>::operator * ()
{
NS_ASSERT_MSG (m_ptr, "Attempted to dereference zero pointer");
return *m_ptr;
}