From e4ceed2bed247c18e3c4d72eca24fa9f7ef64bb1 Mon Sep 17 00:00:00 2001 From: JosJuice Date: Fri, 20 Nov 2020 17:29:11 +0100 Subject: Common: Assert that translatable strings use positional arguments Like PR 9260, but for a different requirement (see PR 9253). --- Source/Core/Common/MsgHandler.h | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'Source/Core/Common/MsgHandler.h') diff --git a/Source/Core/Common/MsgHandler.h b/Source/Core/Common/MsgHandler.h index b06d2e63a9..76164a629b 100644 --- a/Source/Core/Common/MsgHandler.h +++ b/Source/Core/Common/MsgHandler.h @@ -102,6 +102,16 @@ std::string FmtFormatT(const char* string, Args&&... args) ##__VA_ARGS__); \ }() +#define GenericAlertFmtT(yes_no, style, format, ...) \ + [&] { \ + static_assert(!Common::ContainsNonPositionalArguments(format), \ + "Translatable strings must use positional arguments (e.g. {0} instead of {})"); \ + /* Use a macro-like name to avoid shadowing warnings */ \ + constexpr auto GENERIC_ALERT_FMT_N = Common::CountFmtReplacementFields(format); \ + return Common::MsgAlertFmt(yes_no, style, FMT_STRING(format), \ + ##__VA_ARGS__); \ + }() + #define SuccessAlertFmt(format, ...) \ GenericAlertFmt(false, Common::MsgType::Information, format, ##__VA_ARGS__) @@ -119,16 +129,16 @@ std::string FmtFormatT(const char* string, Args&&... args) // Use these macros (that do the same thing) if the message should be translated. #define SuccessAlertFmtT(format, ...) \ - GenericAlertFmt(false, Common::MsgType::Information, format, ##__VA_ARGS__) + GenericAlertFmtT(false, Common::MsgType::Information, format, ##__VA_ARGS__) #define PanicAlertFmtT(format, ...) \ - GenericAlertFmt(false, Common::MsgType::Warning, format, ##__VA_ARGS__) + GenericAlertFmtT(false, Common::MsgType::Warning, format, ##__VA_ARGS__) #define PanicYesNoFmtT(format, ...) \ - GenericAlertFmt(true, Common::MsgType::Warning, format, ##__VA_ARGS__) + GenericAlertFmtT(true, Common::MsgType::Warning, format, ##__VA_ARGS__) #define AskYesNoFmtT(format, ...) \ - GenericAlertFmt(true, Common::MsgType::Question, format, ##__VA_ARGS__) + GenericAlertFmtT(true, Common::MsgType::Question, format, ##__VA_ARGS__) #define CriticalAlertFmtT(format, ...) \ - GenericAlertFmt(false, Common::MsgType::Critical, format, ##__VA_ARGS__) + GenericAlertFmtT(false, Common::MsgType::Critical, format, ##__VA_ARGS__) -- cgit v1.2.3