diff options
author | Kenneth Heafield <github@kheafield.com> | 2011-11-18 16:07:41 +0400 |
---|---|---|
committer | Kenneth Heafield <github@kheafield.com> | 2011-11-18 16:07:41 +0400 |
commit | bf78f7a1acbadbab8da23502d96eb382b60a6b6e (patch) | |
tree | b3ca4bb831bf5f8ea6cd53bbadff2749faa8bca4 /util/check.hh | |
parent | 1192e6f2b045e00fe74060277e7a797a02b53075 (diff) |
Replace assert with CHECK until people learn how to use assert properly
Diffstat (limited to 'util/check.hh')
-rw-r--r-- | util/check.hh | 21 |
1 files changed, 21 insertions, 0 deletions
diff --git a/util/check.hh b/util/check.hh new file mode 100644 index 000000000..2c63b5630 --- /dev/null +++ b/util/check.hh @@ -0,0 +1,21 @@ +/* People have been abusing assert by assuming it will always execute. To + * rememdy the situation, asserts were replaced with CHECK. These should then + * be manually replaced with assert (when used correctly) or UTIL_THROW (for + * runtime checks). + */ +#ifndef UTIL_CHECK__ +#define UTIL_CHECK__ + +#include <stdlib.h> +#include <iostream> + +#include <cassert> + +#define CHECK(Condition) do { \ + if (!(Condition)) { \ + std::cerr << "Check " << #Condition << " failed in " << __FILE__ << ":" << __LINE__ << std::endl; \ + abort(); \ + } \ +} while (0) // swallow ; + +#endif // UTIL_CHECK__ |