Skip to content

Commit

Permalink
error on bool arg w/ char pres_type (fmtlib#3734)
Browse files Browse the repository at this point in the history
  • Loading branch information
js324 authored and happymonkey1 committed Apr 6, 2024
1 parent 6b0f79d commit 6be5371
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 0 deletions.
1 change: 1 addition & 0 deletions include/fmt/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -2429,6 +2429,7 @@ FMT_CONSTEXPR FMT_INLINE auto parse_format_specs(
case 'G':
return parse_presentation_type(pres::general_upper, float_set);
case 'c':
if (arg_type == type::bool_type) throw_format_error("invalid format specifier");
return parse_presentation_type(pres::chr, integral_set);
case 's':
return parse_presentation_type(pres::string,
Expand Down
2 changes: 2 additions & 0 deletions test/format-test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1159,6 +1159,8 @@ TEST(format_test, format_bool) {
EXPECT_EQ("true", fmt::format("{:s}", true));
EXPECT_EQ("false", fmt::format("{:s}", false));
EXPECT_EQ("false ", fmt::format("{:6s}", false));
EXPECT_THROW_MSG((void)fmt::format(runtime("{:c}"), false), format_error,
"invalid format specifier");
}

TEST(format_test, format_short) {
Expand Down

0 comments on commit 6be5371

Please sign in to comment.