diff --git a/include/fmt/core.h b/include/fmt/core.h index f0426093..22768ff8 100644 --- a/include/fmt/core.h +++ b/include/fmt/core.h @@ -2577,8 +2577,8 @@ FMT_CONSTEXPR auto check_cstring_type_spec(Char spec, ErrorHandler&& eh = {}) return false; } -template -FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh) { +template +FMT_CONSTEXPR void check_string_type_spec(Char spec, ErrorHandler&& eh = {}) { if (spec != 0 && spec != 's') eh.on_error("invalid type specifier"); } diff --git a/include/fmt/format.h b/include/fmt/format.h index 7de8e98f..0024cf7c 100644 --- a/include/fmt/format.h +++ b/include/fmt/format.h @@ -1569,6 +1569,7 @@ FMT_CONSTEXPR auto write(OutputIt out, basic_string_view> s, const basic_format_specs& specs, locale_ref) -> OutputIt { + check_string_type_spec(specs.type); return write(out, s, specs); } template diff --git a/test/format-test.cc b/test/format-test.cc index 892556f1..ec59a5fc 100644 --- a/test/format-test.cc +++ b/test/format-test.cc @@ -1390,6 +1390,8 @@ TEST(format_test, format_pointer) { TEST(format_test, format_string) { EXPECT_EQ("test", fmt::format("{0}", std::string("test"))); + EXPECT_THROW(fmt::format(fmt::runtime("{:x}"), std::string("test")), + fmt::format_error); } TEST(format_test, format_string_view) {