Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/moses-smt/mosesdecoder.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
path: root/util
diff options
context:
space:
mode:
authorKenneth Heafield <github@kheafield.com>2011-11-18 16:07:41 +0400
committerKenneth Heafield <github@kheafield.com>2011-11-18 16:07:41 +0400
commitbf78f7a1acbadbab8da23502d96eb382b60a6b6e (patch)
treeb3ca4bb831bf5f8ea6cd53bbadff2749faa8bca4 /util
parent1192e6f2b045e00fe74060277e7a797a02b53075 (diff)
Replace assert with CHECK until people learn how to use assert properly
Diffstat (limited to 'util')
-rw-r--r--util/check.hh21
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__