mirror of
https://github.com/fmtlib/fmt.git
synced 2025-07-30 02:37:36 +02:00
Annotate fmt::format and fmt::formatted_size as [[nodiscard]]
This prevents accidentally writing fmt::format when fmt::print was intended. Other than running tests, there's not a good use case for discarding the formatted output.
This commit is contained in:
committed by
Victor Zverovich
parent
5abe9e8266
commit
491ba2dda5
@ -17,12 +17,12 @@
|
||||
|
||||
// Exercise the API to verify that everything we expect to can compile.
|
||||
void test_format_api() {
|
||||
fmt::format(FMT_STRING("{}"), 42);
|
||||
fmt::format(FMT_STRING(L"{}"), 42);
|
||||
fmt::format(FMT_STRING("noop"));
|
||||
(void)fmt::format(FMT_STRING("{}"), 42);
|
||||
(void)fmt::format(FMT_STRING(L"{}"), 42);
|
||||
(void)fmt::format(FMT_STRING("noop"));
|
||||
|
||||
fmt::to_string(42);
|
||||
fmt::to_wstring(42);
|
||||
(void)fmt::to_string(42);
|
||||
(void)fmt::to_wstring(42);
|
||||
|
||||
std::vector<char> out;
|
||||
fmt::format_to(std::back_inserter(out), FMT_STRING("{}"), 42);
|
||||
@ -35,13 +35,13 @@ void test_format_api() {
|
||||
}
|
||||
|
||||
void test_chrono() {
|
||||
fmt::format(FMT_STRING("{}"), std::chrono::seconds(42));
|
||||
fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42));
|
||||
(void)fmt::format(FMT_STRING("{}"), std::chrono::seconds(42));
|
||||
(void)fmt::format(FMT_STRING(L"{}"), std::chrono::seconds(42));
|
||||
}
|
||||
|
||||
void test_text_style() {
|
||||
fmt::print(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
||||
fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
||||
(void)fmt::format(fg(fmt::rgb(255, 20, 30)), FMT_STRING("{}"), "rgb(255,20,30)");
|
||||
|
||||
fmt::text_style ts = fg(fmt::rgb(255, 20, 30));
|
||||
std::string out;
|
||||
@ -51,7 +51,7 @@ void test_text_style() {
|
||||
|
||||
void test_range() {
|
||||
std::vector<char> hello = {'h', 'e', 'l', 'l', 'o'};
|
||||
fmt::format(FMT_STRING("{}"), hello);
|
||||
(void)fmt::format(FMT_STRING("{}"), hello);
|
||||
}
|
||||
|
||||
int main() {
|
||||
|
Reference in New Issue
Block a user