Unless HasReason
gets a new ctor that takes non-ref string
which we can std::move
into (and it can move
from internally into the member), we are now allocating extra string
copies on every FailFmtWithError
-call.
I prefer going back to string_view
here.
Yet another possible alternative is to construct HasReason
copies outside and pass them in. Nice to memory badbut slightly ugly using HasReason
outside of the Boost macro.
0diff --git a/src/test/util_string_tests.cpp b/src/test/util_string_tests.cpp
1index 4f9aa197f9..5850102152 100644
2--- a/src/test/util_string_tests.cpp
3+++ b/src/test/util_string_tests.cpp
4@@ -20,9 +20,9 @@ inline void PassFmt(util::ConstevalFormatString<NumArgs> fmt)
5 decltype(fmt)::Detail_CheckNumFormatSpecifiers(fmt.fmt);
6 }
7 template <unsigned WrongNumArgs>
8-inline void FailFmtWithError(std::string_view wrong_fmt, std::string error)
9+inline void FailFmtWithError(std::string_view wrong_fmt, const HasReason& error)
10 {
11- BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), const char*, HasReason(error));
12+ BOOST_CHECK_EXCEPTION(util::ConstevalFormatString<WrongNumArgs>::Detail_CheckNumFormatSpecifiers(wrong_fmt), const char*, error);
13 }
14
15 BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
16@@ -61,23 +61,23 @@ BOOST_AUTO_TEST_CASE(ConstevalFormatString_NumSpec)
17 PassFmt<2>("%2$*3$d");
18 PassFmt<1>("%.*f");
19
20- auto err_mix{"Format specifiers must be all positional or all non-positional!"};
21+ HasReason err_mix{"Format specifiers must be all positional or all non-positional!"};
22 FailFmtWithError<1>("%s%1$s", err_mix);
23
24- auto err_num{"Format specifier count must match the argument count!"};
25+ HasReason err_num{"Format specifier count must match the argument count!"};
26 FailFmtWithError<1>("", err_num);
27 FailFmtWithError<0>("%s", err_num);
28 FailFmtWithError<2>("%s", err_num);
29 FailFmtWithError<0>("%1$s", err_num);
30 FailFmtWithError<2>("%1$s", err_num);
31
32- auto err_0_pos{"Positional format specifier must have position of at least 1"};
33+ HasReason err_0_pos{"Positional format specifier must have position of at least 1"};
34 FailFmtWithError<1>("%$s", err_0_pos);
35 FailFmtWithError<1>("%$", err_0_pos);
36 FailFmtWithError<0>("%0$", err_0_pos);
37 FailFmtWithError<0>("%0$s", err_0_pos);
38
39- auto err_term{"Format specifier incorrectly terminated by end of string"};
40+ HasReason err_term{"Format specifier incorrectly terminated by end of string"};
41 FailFmtWithError<1>("%", err_term);
42 FailFmtWithError<1>("%1$", err_term);
43 }