Skip to content

Commit ffe414c

Browse files
committed
Add compile-time format string checks to format_to (#783)
1 parent c178ab4 commit ffe414c

File tree

1 file changed

+8
-11
lines changed

1 file changed

+8
-11
lines changed

include/fmt/format.h

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3524,19 +3524,16 @@ inline wformat_context::iterator vformat_to(
35243524
return vformat_to<arg_formatter<range>>(buf, format_str, args);
35253525
}
35263526

3527-
template <typename... Args, std::size_t SIZE = inline_buffer_size>
3527+
template <typename String, typename... Args,
3528+
std::size_t SIZE = inline_buffer_size>
35283529
inline format_context::iterator format_to(
3529-
basic_memory_buffer<char, SIZE> &buf, string_view format_str,
3530+
basic_memory_buffer<char, SIZE> &buf, const String &format_str,
35303531
const Args & ... args) {
3531-
return vformat_to(buf, format_str, make_format_args(args...));
3532-
}
3533-
3534-
template <typename... Args, std::size_t SIZE = inline_buffer_size>
3535-
inline wformat_context::iterator format_to(
3536-
basic_memory_buffer<wchar_t, SIZE> &buf, wstring_view format_str,
3537-
const Args & ... args) {
3538-
return vformat_to(buf, format_str,
3539-
make_format_args<wformat_context>(args...));
3532+
internal::check_format_string<Args...>(format_str);
3533+
typedef typename internal::format_string_traits<String>::char_type char_t;
3534+
return vformat_to(
3535+
buf, basic_string_view<char_t>(format_str),
3536+
make_format_args<typename buffer_context<char_t>::type>(args...));
35403537
}
35413538

35423539
template <typename OutputIt, typename Char = char>

0 commit comments

Comments
 (0)