mirror of
https://github.com/bitcoin/bitcoin.git
synced 2025-03-12 10:30:08 +01:00
logging: Add preprocessor workaround for MSVC
Needed to fix errors like: const Source &_LogSource(const Source &)': expects 1 arguments - 3 provided const Source &_LogSource(const Source &)': expects 1 arguments - 3 provided due to a compiler bug: https://stackoverflow.com/questions/5134523/msvc-doesnt-expand-va-args-correctly/5134656#5134656 Example CI failure: https://github.com/bitcoin/bitcoin/actions/runs/8072891468/job/22055528830?pr=29256
This commit is contained in:
parent
12d97dbdcb
commit
5db1958e60
1 changed files with 7 additions and 4 deletions
|
@ -299,18 +299,21 @@ void _LogFormat(LogFn&& log, Source&& source, util::ConstevalFormatString<sizeof
|
||||||
log(source, source.Format(fmt, args...));
|
log(source, source.Format(fmt, args...));
|
||||||
}
|
}
|
||||||
|
|
||||||
//! Internal helper to return first arg in a __VA_ARGS__ pack.
|
//! Internal helper to return first arg in a __VA_ARGS__ pack. This could be
|
||||||
#define _FirstArg(arg, ...) arg
|
//! simplified to `#define _FirstArg(arg, ...) arg` if not for a preprocessor
|
||||||
|
//! bug in Visual C++.
|
||||||
|
#define _FirstArgImpl(arg, ...) arg
|
||||||
|
#define _FirstArg(args) _FirstArgImpl args
|
||||||
|
|
||||||
//! Internal helper to check level and log. Avoids evaluating arguments if not logging.
|
//! Internal helper to check level and log. Avoids evaluating arguments if not logging.
|
||||||
#define _LogPrint(level, ...) \
|
#define _LogPrint(level, ...) \
|
||||||
do { \
|
do { \
|
||||||
if (LogEnabled(_LogSource(_FirstArg(__VA_ARGS__)), (level))) { \
|
if (LogEnabled(_LogSource(_FirstArg((__VA_ARGS__))), (level))) { \
|
||||||
const auto& func = __func__; \
|
const auto& func = __func__; \
|
||||||
_LogFormat([&](auto&& source, auto&& message) { \
|
_LogFormat([&](auto&& source, auto&& message) { \
|
||||||
source.logger.LogPrintStr(message, func, __FILE__, \
|
source.logger.LogPrintStr(message, func, __FILE__, \
|
||||||
__LINE__, source.category, (level)); \
|
__LINE__, source.category, (level)); \
|
||||||
}, _LogSource(_FirstArg(__VA_ARGS__)), __VA_ARGS__); \
|
}, _LogSource(_FirstArg((__VA_ARGS__))), __VA_ARGS__); \
|
||||||
} \
|
} \
|
||||||
} while (0)
|
} while (0)
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue