You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
MB-46216: Check log format strings at compile-time (ep-engine)
Make use of the FMT_STRING macro to check format strings at
compile-time using fmtlib v7 in ep-engine.
If a call to the logger omits one or more arguments, then a
compile-time error will be seen - given the following (incorrect) call
missing a argument for 'bar':
EP_LOG_DEBUG("Foo:{} bar:{}", foo);
The compiler fails with:
fmt/format.h:2873:27: constexpr variable 'invalid_format' must be initialized by a constant expression
(admittedly not the most obvious, but you get what you get with C++
compiler errors...)
Note that this now requires that the EP_LOG_<LEVEL> macros always take
a valid fmtlib format string as the first argument, a raw string
literal is no longer supported - the following will no longer compile:
EP_LOG_DEBUG("Something happened"); // compile-time error.
Instead, the _RAW macros added in the previous patch should be used:
EP_LOG_DEBUG_RAW("Something else happened"); OK
Note: The issue here is that to perform compile-time format string
checking, the format string must be wrapped in FMT_STRING() -
before the format string is evaluated / passed into the actual
logging functions / methods. However, one cannot pass a
non-string literal to FMT_STRING - essentially by design it
fails at compile-time if it doesn't have {} placeholders.
To address this (and still allow both styles of parameters) we
_could_ in theory do some complex preprocessor logic - count the
number of variadic arguments at compile-time and only apply
FMT_STRING() macro to first if there is 2 or more arguments in
total. I got something working for GCC and clang and which did
this, but it didn't work for MSVC and the GCC one triggered a
load of warnings, hence just making original macros always
fmt-style, and adding _RAW for plan unformatted values.
Change-Id: I32c37dfc9672663e5741433885787f1e941fe795
Reviewed-on: http://review.couchbase.org/c/kv_engine/+/153272
Tested-by: Dave Rigby <daver@couchbase.com>
Reviewed-by: Ben Huddleston <ben.huddleston@couchbase.com>
0 commit comments