Merge pull request #11008 from Pokechu22/va_opt

Use `__VA_OPT__(, ) __VA_ARGS__` instead of `##__VA_ARGS__`
This commit is contained in:
Pokechu22 2022-08-23 14:12:55 -07:00 committed by GitHub
commit f18d787d4a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 33 additions and 26 deletions

View File

@ -1,5 +1,5 @@
if (NOT MSVC) if (NOT MSVC)
set(CMAKE_CXX_STANDARD 17) set(CMAKE_CXX_STANDARD 20)
set(CMAKE_CXX_STANDARD_REQUIRED ON) set(CMAKE_CXX_STANDARD_REQUIRED ON)
set(CMAKE_CXX_EXTENSIONS OFF) set(CMAKE_CXX_EXTENSIONS OFF)
endif() endif()

View File

@ -17,7 +17,7 @@
"An error occurred.\n\n" _fmt_ "\n\n" \ "An error occurred.\n\n" _fmt_ "\n\n" \
" Condition: {}\n File: {}\n Line: {}\n Function: {}\n\n" \ " Condition: {}\n File: {}\n Line: {}\n Function: {}\n\n" \
"Ignore and continue?", \ "Ignore and continue?", \
##__VA_ARGS__, #_a_, __FILE__, __LINE__, __func__)) \ __VA_ARGS__ __VA_OPT__(, ) #_a_, __FILE__, __LINE__, __func__)) \
Crash(); \ Crash(); \
} \ } \
} while (0) } while (0)
@ -26,7 +26,7 @@
do \ do \
{ \ { \
if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \ if constexpr (Common::Log::MAX_LOGLEVEL >= Common::Log::LogLevel::LDEBUG) \
ASSERT_MSG(_t_, _a_, _fmt_, ##__VA_ARGS__); \ ASSERT_MSG(_t_, _a_, _fmt_ __VA_OPT__(, ) __VA_ARGS__); \
} while (0) } while (0)
#define ASSERT(_a_) \ #define ASSERT(_a_) \

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 */ \ /* Use a macro-like name to avoid shadowing warnings */ \
constexpr auto GENERIC_LOG_FMT_N = Common::CountFmtReplacementFields(format); \ constexpr auto GENERIC_LOG_FMT_N = Common::CountFmtReplacementFields(format); \
Common::Log::GenericLogFmt<GENERIC_LOG_FMT_N>(v, t, __FILE__, __LINE__, FMT_STRING(format), \ Common::Log::GenericLogFmt<GENERIC_LOG_FMT_N>( \
##__VA_ARGS__); \ v, t, __FILE__, __LINE__, FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__); \
} \ } \
} while (0) } while (0)
#define ERROR_LOG_FMT(t, ...) \ #define ERROR_LOG_FMT(t, ...) \
do \ 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) } while (0)
#define WARN_LOG_FMT(t, ...) \ #define WARN_LOG_FMT(t, ...) \
do \ 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) } while (0)
#define NOTICE_LOG_FMT(t, ...) \ #define NOTICE_LOG_FMT(t, ...) \
do \ 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) } while (0)
#define INFO_LOG_FMT(t, ...) \ #define INFO_LOG_FMT(t, ...) \
do \ 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) } while (0)
#define DEBUG_LOG_FMT(t, ...) \ #define DEBUG_LOG_FMT(t, ...) \
do \ 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) } while (0)

View File

@ -84,46 +84,48 @@ std::string FmtFormatT(const char* string, Args&&... args)
#define GenericAlertFmt(yes_no, style, log_type, format, ...) \ #define GenericAlertFmt(yes_no, style, log_type, format, ...) \
Common::MsgAlertFmt<Common::CountFmtReplacementFields(format)>( \ Common::MsgAlertFmt<Common::CountFmtReplacementFields(format)>( \
yes_no, style, Common::Log::LogType::log_type, __FILE__, __LINE__, FMT_STRING(format), \ yes_no, style, Common::Log::LogType::log_type, __FILE__, __LINE__, \
##__VA_ARGS__) FMT_STRING(format) __VA_OPT__(, ) __VA_ARGS__)
#define GenericAlertFmtT(yes_no, style, log_type, format, ...) \ #define GenericAlertFmtT(yes_no, style, log_type, format, ...) \
Common::MsgAlertFmtT<Common::CountFmtReplacementFields(format), \ Common::MsgAlertFmtT<Common::CountFmtReplacementFields(format), \
Common::ContainsNonPositionalArguments(format)>( \ Common::ContainsNonPositionalArguments(format)>( \
yes_no, style, Common::Log::LogType::log_type, __FILE__, __LINE__, FMT_STRING(format), \ yes_no, style, Common::Log::LogType::log_type, __FILE__, __LINE__, FMT_STRING(format), \
Common::GetStringT(format), ##__VA_ARGS__) Common::GetStringT(format) __VA_OPT__(, ) __VA_ARGS__)
#define SuccessAlertFmt(format, ...) \ #define SuccessAlertFmt(format, ...) \
GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmt(false, Common::MsgType::Information, MASTER_LOG, \
format __VA_OPT__(, ) __VA_ARGS__)
#define PanicAlertFmt(format, ...) \ #define PanicAlertFmt(format, ...) \
GenericAlertFmt(false, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmt(false, Common::MsgType::Warning, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
#define PanicYesNoFmt(format, ...) \ #define PanicYesNoFmt(format, ...) \
GenericAlertFmt(true, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmt(true, Common::MsgType::Warning, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
#define AskYesNoFmt(format, ...) \ #define AskYesNoFmt(format, ...) \
GenericAlertFmt(true, Common::MsgType::Question, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmt(true, Common::MsgType::Question, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
#define CriticalAlertFmt(format, ...) \ #define CriticalAlertFmt(format, ...) \
GenericAlertFmt(false, Common::MsgType::Critical, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmt(false, Common::MsgType::Critical, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
// Use these macros (that do the same thing) if the message should be translated. // Use these macros (that do the same thing) if the message should be translated.
#define SuccessAlertFmtT(format, ...) \ #define SuccessAlertFmtT(format, ...) \
GenericAlertFmtT(false, Common::MsgType::Information, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmtT(false, Common::MsgType::Information, MASTER_LOG, \
format __VA_OPT__(, ) __VA_ARGS__)
#define PanicAlertFmtT(format, ...) \ #define PanicAlertFmtT(format, ...) \
GenericAlertFmtT(false, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmtT(false, Common::MsgType::Warning, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
#define PanicYesNoFmtT(format, ...) \ #define PanicYesNoFmtT(format, ...) \
GenericAlertFmtT(true, Common::MsgType::Warning, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmtT(true, Common::MsgType::Warning, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
#define AskYesNoFmtT(format, ...) \ #define AskYesNoFmtT(format, ...) \
GenericAlertFmtT(true, Common::MsgType::Question, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmtT(true, Common::MsgType::Question, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
#define CriticalAlertFmtT(format, ...) \ #define CriticalAlertFmtT(format, ...) \
GenericAlertFmtT(false, Common::MsgType::Critical, MASTER_LOG, format, ##__VA_ARGS__) GenericAlertFmtT(false, Common::MsgType::Critical, MASTER_LOG, format __VA_OPT__(, ) __VA_ARGS__)
// Variant that takes a log type, used by the assert macros // Variant that takes a log type, used by the assert macros
#define PanicYesNoFmtAssert(log_type, format, ...) \ #define PanicYesNoFmtAssert(log_type, format, ...) \
GenericAlertFmt(true, Common::MsgType::Warning, log_type, format, ##__VA_ARGS__) GenericAlertFmt(true, Common::MsgType::Warning, log_type, format __VA_OPT__(, ) __VA_ARGS__)

View File

@ -51,6 +51,6 @@ void LogVulkanResult(Common::Log::LogLevel level, const char* func_name, VkResul
const char* msg, ...); const char* msg, ...);
#define LOG_VULKAN_ERROR(res, ...) \ #define LOG_VULKAN_ERROR(res, ...) \
LogVulkanResult(Common::Log::LogLevel::LERROR, __func__, res, __VA_ARGS__) LogVulkanResult(Common::Log::LogLevel::LERROR, __func__, res __VA_OPT__(, ) __VA_ARGS__)
} // namespace Vulkan } // namespace Vulkan

View File

@ -24,7 +24,7 @@ constexpr u32 MAX_XFB_WIDTH = 720;
// that are next to each other in memory (TODO: handle that situation). // that are next to each other in memory (TODO: handle that situation).
constexpr u32 MAX_XFB_HEIGHT = 576; constexpr u32 MAX_XFB_HEIGHT = 576;
#define PRIM_LOG(...) DEBUG_LOG_FMT(VIDEO, ##__VA_ARGS__) #define PRIM_LOG(t, ...) DEBUG_LOG_FMT(VIDEO, t __VA_OPT__(, ) __VA_ARGS__)
// warning: mapping buffer should be disabled to use this // warning: mapping buffer should be disabled to use this
// #define LOG_VTX() DEBUG_LOG_FMT(VIDEO, "vtx: {} {} {}, ", // #define LOG_VTX() DEBUG_LOG_FMT(VIDEO, "vtx: {} {} {}, ",