Make error handling more convenient

By adding some PRAY_* macros that encapsulate both the check and the returning of a null reference (UB).
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:07:39 +02:00
parent 21bf3778d5
commit e9b7640f84
8 changed files with 66 additions and 34 deletions

View file

@ -599,9 +599,9 @@ public:
const V &operator[](const K &p_key) const {
ERR_FAIL_COND_V(!_data._root, *(V *)NULL); // crash on purpose
PRAY_COND(!_data._root, V);
const Element *e = find(p_key);
ERR_FAIL_COND_V(!e, *(V *)NULL); // crash on purpose
PRAY_COND(!e, V);
return e->_value;
}
V &operator[](const K &p_key) {
@ -613,7 +613,7 @@ public:
if (!e)
e = insert(p_key, V());
ERR_FAIL_COND_V(!e, *(V *)NULL); // crash on purpose
PRAY_COND(!e, V);
return e->_value;
}