Common/MsgHandler: Remove use of lambda, as it breaks __func__

Specifically, this meant that __func__ in macros (namely ASSERT) would always be evaluate to "operator ()".
This commit is contained in:
Pokechu22 2021-11-10 19:38:02 -08:00
parent 558de04cfc
commit 2a5016c2f8
1 changed files with 18 additions and 14 deletions

View File

@ -45,6 +45,19 @@ bool MsgAlertFmt(bool yes_no, MsgType style, Common::Log::LogType log_type, cons
fmt::make_args_checked<Args...>(format, args...)); fmt::make_args_checked<Args...>(format, args...));
} }
template <std::size_t NumFields, bool has_non_positional_args, typename S, typename... Args>
bool MsgAlertFmtT(bool yes_no, MsgType style, Common::Log::LogType log_type, const S& format,
const Args&... args)
{
static_assert(!has_non_positional_args,
"Translatable strings must use positional arguments (e.g. {0} instead of {})");
static_assert(NumFields == sizeof...(args),
"Unexpected number of replacement fields in format string; did you pass too few or "
"too many arguments?");
return MsgAlertFmtImpl(yes_no, style, log_type, format,
fmt::make_args_checked<Args...>(format, args...));
}
void SetEnableAlert(bool enable); void SetEnableAlert(bool enable);
void SetAbortOnPanicAlert(bool should_abort); void SetAbortOnPanicAlert(bool should_abort);
@ -59,22 +72,13 @@ std::string FmtFormatT(const char* string, Args&&... args)
// Fmt-capable variants of the macros // Fmt-capable variants of the macros
#define GenericAlertFmt(yes_no, style, log_type, format, ...) \ #define GenericAlertFmt(yes_no, style, log_type, format, ...) \
[&] { \ Common::MsgAlertFmt<Common::CountFmtReplacementFields(format)>( \
/* Use a macro-like name to avoid shadowing warnings */ \ yes_no, style, Common::Log::LogType::log_type, FMT_STRING(format), ##__VA_ARGS__)
constexpr auto GENERIC_ALERT_FMT_N = Common::CountFmtReplacementFields(format); \
return Common::MsgAlertFmt<GENERIC_ALERT_FMT_N>(yes_no, style, Common::Log::LogType::log_type, \
FMT_STRING(format), ##__VA_ARGS__); \
}()
#define GenericAlertFmtT(yes_no, style, log_type, format, ...) \ #define GenericAlertFmtT(yes_no, style, log_type, format, ...) \
[&] { \ Common::MsgAlertFmtT<Common::CountFmtReplacementFields(format), \
static_assert(!Common::ContainsNonPositionalArguments(format), \ Common::ContainsNonPositionalArguments(format)>( \
"Translatable strings must use positional arguments (e.g. {0} instead of {})"); \ yes_no, style, Common::Log::LogType::log_type, FMT_STRING(format), ##__VA_ARGS__)
/* Use a macro-like name to avoid shadowing warnings */ \
constexpr auto GENERIC_ALERT_FMT_N = Common::CountFmtReplacementFields(format); \
return Common::MsgAlertFmt<GENERIC_ALERT_FMT_N>(yes_no, style, Common::Log::LogType::log_type, \
FMT_STRING(format), ##__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_ARGS__)