error on bool arg w/ char pres_type (#3734)

This commit is contained in:
js324 2023-12-05 16:45:10 -05:00 committed by GitHub
parent 5d55375a8a
commit 573d74395b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 3 additions and 0 deletions

View File

@ -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,

View File

@ -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) {