Skip to content

Commit 688556a

Browse files
committedOct 28, 2015
Add STATIC_ASSERT() macro and use it
1 parent c56d7fe commit 688556a

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed
 

Diff for: ‎src/basicmacros.h

+5
Original file line numberDiff line numberDiff line change
@@ -38,4 +38,9 @@ with this program; if not, write to the Free Software Foundation, Inc.,
3838
C(const C &); \
3939
C &operator=(const C &)
4040

41+
// Fail compilation if condition expr is not met.
42+
// Note that 'msg' must follow the format of a valid identifier, e.g.
43+
// STATIC_ASSERT(sizeof(foobar_t) == 40), foobar_t_is_wrong_size);
44+
#define STATIC_ASSERT(expr, msg) typedef char msg[!!(expr) * 2 - 1]
45+
4146
#endif

Diff for: ‎src/log.cpp

+4-2
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,8 @@ class AndroidSystemLogOutput : public ICombinedLogOutput {
135135
}
136136
void logRaw(LogLevel lev, const std::string &line)
137137
{
138-
assert(ARRLEN(g_level_to_android) == LL_MAX);
138+
STATIC_ASSERT(ARRLEN(g_level_to_android) == LL_MAX,
139+
mismatch_between_android_and_internal_loglevels);
139140
__android_log_print(g_level_to_android[lev],
140141
PROJECT_NAME_C, "%s", line.c_str());
141142
}
@@ -228,7 +229,8 @@ const std::string Logger::getLevelLabel(LogLevel lev)
228229
"VERBOSE",
229230
};
230231
assert(lev < LL_MAX && lev >= 0);
231-
assert(ARRLEN(names) == LL_MAX);
232+
STATIC_ASSERT(ARRLEN(names) == LL_MAX,
233+
mismatch_between_loglevel_names_and_enum);
232234
return names[lev];
233235
}
234236

0 commit comments

Comments
 (0)