Carved out of #30928 - this PR doesn’t include the controversial change of suppressing tinyformat::format_error throwing behaviour, and just adds enforcement of compile-time checks for format string literals.
Reduce unexpected run-time crashes from string formatting by enforcing compile-time format string checks for most* tfm::format and strprintf usage.
This PR should introduce no behaviour change. The main changes are:
- remove the
const std::string&tfm::formatoverload since it’s not necessary. Usage of this overload is removed by one of:- replacing string concatenation in the format string with just an extra parameter
- using the
bilingual_stroverload - using the new
tfm::format_rawfunctions (only for tinyformat implementation or tests)
- rename the non-compile-time-validated
tfm::formatoverloads totfm::format_raw, so existing callsites by default use the saferutil::ConstevalFormatStringtfm::formatoverloads. Callsites that for some reason don’t pass the compile-time checks (such as inbitcoin-cli.cpp) can usetfm::format_raw.
See #31149 (review) for an example on how this PR can prevent a run-time error for a small format string mistake.
* See #31061 for bilingual_str format(const bilingual_str& fmt, const Args&... args) compile-time checks.