Implement well-defined handling of unrecoverable errors

Plus the addition of some convenience CRASH_* error macros.
Plus transient avoidance of the flood of warnings emitted by Clang when checking 'this' for NULL.
Plus explanation about the do-while(0) loop in some error macros.
This commit is contained in:
Pedro J. Estébanez
2017-05-26 21:11:16 +02:00
parent 9fa4f1c54c
commit 211c451890
8 changed files with 76 additions and 45 deletions

View File

@ -134,10 +134,7 @@ public:
inline T &operator[](int p_index) {
if (p_index < 0 || p_index >= size()) {
T &aux = *((T *)0); //nullreturn
ERR_FAIL_COND_V(p_index < 0 || p_index >= size(), aux);
}
CRASH_BAD_INDEX(p_index, size());
_copy_on_write(); // wants to write, so copy on write.
@ -146,10 +143,8 @@ public:
inline const T &operator[](int p_index) const {
if (p_index < 0 || p_index >= size()) {
const T &aux = *((T *)0); //nullreturn
ERR_FAIL_COND_V(p_index < 0 || p_index >= size(), aux);
}
CRASH_BAD_INDEX(p_index, size());
// no cow needed, since it's reading
return _get_data()[p_index];
}