Use __VA_OPT__(, ) __VA_ARGS__ instead of ##__VA_ARGS__

Per https://en.cppreference.com/w/cpp/preprocessor/replace#.23_and_.23.23_operators the `##` behavior is a nonstandard extension; this extension seems to be supported by all compilers we care about, but IntelliSense in visual studio doesn't correctly handle it, resulting in false errors in the IDE (but not when compiling).

Per https://en.cppreference.com/w/cpp/preprocessor/replace#Function-like_macros C++20 introduced a workaround, where `__VA_OPT__(, )` generates a comma if and only if `__VA_ARGS__` is non-empty.

This PR replaces all occurrences, with the exception of Externals, DSPSpy (which is not likely to be edited in MSVC and does not target C++20 currently), and JitArm64_Integer.cpp (which uses `Function(__VA_ARGS__)`, and thus does not ever need a comma).
This commit is contained in:
Pokechu22
2022-08-23 11:14:47 -07:00
parent 0fcff9f5ea
commit 0cced44142
5 changed files with 32 additions and 25 deletions

View File

@ -111,33 +111,38 @@ void GenericLogFmt(LogLevel level, LogType type, const char* file, int line, con
{ \
/* Use a macro-like name to avoid shadowing warnings */ \
constexpr auto GENERIC_LOG_FMT_N = Common::CountFmtReplacementFields(format); \
Common::Log::GenericLogFmt<GENERIC_LOG_FMT_N>(v, t, __FILE__, __LINE__, FMT_STRING(format), \
##__VA_ARGS__); \
Common::Log::GenericLogFmt<GENERIC_LOG_FMT_N>( \
v, t, __FILE__, __LINE__, FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \
} \
} while (0)
#define ERROR_LOG_FMT(t, ...) \
do \
{ \
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LERROR, __VA_ARGS__); \
GENERIC_LOG_FMT(Common::Log::LogType::t, \
Common::Log::LogLevel::LERROR __VA_OPT__(, ) __VA_ARGS__); \
} while (0)
#define WARN_LOG_FMT(t, ...) \
do \
{ \
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LWARNING, __VA_ARGS__); \
GENERIC_LOG_FMT(Common::Log::LogType::t, \
Common::Log::LogLevel::LWARNING __VA_OPT__(, ) __VA_ARGS__); \
} while (0)
#define NOTICE_LOG_FMT(t, ...) \
do \
{ \
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LNOTICE, __VA_ARGS__); \
GENERIC_LOG_FMT(Common::Log::LogType::t, \
Common::Log::LogLevel::LNOTICE __VA_OPT__(, ) __VA_ARGS__); \
} while (0)
#define INFO_LOG_FMT(t, ...) \
do \
{ \
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LINFO, __VA_ARGS__); \
GENERIC_LOG_FMT(Common::Log::LogType::t, \
Common::Log::LogLevel::LINFO __VA_OPT__(, ) __VA_ARGS__); \
} while (0)
#define DEBUG_LOG_FMT(t, ...) \
do \
{ \
GENERIC_LOG_FMT(Common::Log::LogType::t, Common::Log::LogLevel::LDEBUG, __VA_ARGS__); \
GENERIC_LOG_FMT(Common::Log::LogType::t, \
Common::Log::LogLevel::LDEBUG __VA_OPT__(, ) __VA_ARGS__); \
} while (0)