aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorkwolekr <kwolekr@minetest.net>2015-10-27 22:27:32 -0400
committerkwolekr <kwolekr@minetest.net>2015-10-27 22:27:32 -0400
commit688556a5d1910ead2cf06a87af6908110fa9d035 (patch)
treefb0fc91212847ca73b9ec83162f5f5c075bcb314
parentc56d7fe0eba7905b0a63c4a1cfe909988653c23d (diff)
downloadminetest-688556a5d1910ead2cf06a87af6908110fa9d035.tar.gz
minetest-688556a5d1910ead2cf06a87af6908110fa9d035.tar.bz2
minetest-688556a5d1910ead2cf06a87af6908110fa9d035.zip
Add STATIC_ASSERT() macro and use it
-rw-r--r--src/basicmacros.h5
-rw-r--r--src/log.cpp6
2 files changed, 9 insertions, 2 deletions
diff --git a/src/basicmacros.h b/src/basicmacros.h
index cebf06043..2a30a31d2 100644
--- a/src/basicmacros.h
+++ b/src/basicmacros.h
@@ -38,4 +38,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
C(const C &); \
C &operator=(const C &)
+// Fail compilation if condition expr is not met.
+// Note that 'msg' must follow the format of a valid identifier, e.g.
+// STATIC_ASSERT(sizeof(foobar_t) == 40), foobar_t_is_wrong_size);
+#define STATIC_ASSERT(expr, msg) typedef char msg[!!(expr) * 2 - 1]
+
#endif
diff --git a/src/log.cpp b/src/log.cpp
index 3ffd66673..5cba8f700 100644
--- a/src/log.cpp
+++ b/src/log.cpp
@@ -135,7 +135,8 @@ class AndroidSystemLogOutput : public ICombinedLogOutput {
}
void logRaw(LogLevel lev, const std::string &line)
{
- assert(ARRLEN(g_level_to_android) == LL_MAX);
+ STATIC_ASSERT(ARRLEN(g_level_to_android) == LL_MAX,
+ mismatch_between_android_and_internal_loglevels);
__android_log_print(g_level_to_android[lev],
PROJECT_NAME_C, "%s", line.c_str());
}
@@ -228,7 +229,8 @@ const std::string Logger::getLevelLabel(LogLevel lev)
"VERBOSE",
};
assert(lev < LL_MAX && lev >= 0);
- assert(ARRLEN(names) == LL_MAX);
+ STATIC_ASSERT(ARRLEN(names) == LL_MAX,
+ mismatch_between_loglevel_names_and_enum);
return names[lev];
}