mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-24 12:14:26 +00:00
Disallow formatting of multibyte strings into a wide buffer (#606)
This commit is contained in:
parent
ca93be130a
commit
daf650c49a
@ -546,7 +546,7 @@ template <typename Context, typename T>
|
|||||||
FMT_CONSTEXPR basic_arg<Context> make_arg(const T &value);
|
FMT_CONSTEXPR basic_arg<Context> make_arg(const T &value);
|
||||||
|
|
||||||
#define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \
|
#define FMT_MAKE_VALUE(TAG, ArgType, ValueType) \
|
||||||
template <typename C, typename Char = typename C::char_type> \
|
template <typename C> \
|
||||||
FMT_CONSTEXPR typed_value<C, TAG> make_value(ArgType val) { \
|
FMT_CONSTEXPR typed_value<C, TAG> make_value(ArgType val) { \
|
||||||
return static_cast<ValueType>(val); \
|
return static_cast<ValueType>(val); \
|
||||||
}
|
}
|
||||||
@ -589,20 +589,22 @@ FMT_MAKE_VALUE(long_double_type, long double, long double)
|
|||||||
|
|
||||||
// Formatting of wide strings into a narrow buffer and multibyte strings
|
// Formatting of wide strings into a narrow buffer and multibyte strings
|
||||||
// into a wide buffer is disallowed (https://github.com/fmtlib/fmt/pull/606).
|
// into a wide buffer is disallowed (https://github.com/fmtlib/fmt/pull/606).
|
||||||
FMT_MAKE_VALUE(cstring_type, Char*, const Char*)
|
FMT_MAKE_VALUE(cstring_type, typename C::char_type*,
|
||||||
FMT_MAKE_VALUE(cstring_type, const Char*, const Char*)
|
const typename C::char_type*)
|
||||||
|
FMT_MAKE_VALUE(cstring_type, const typename C::char_type*,
|
||||||
|
const typename C::char_type*)
|
||||||
|
|
||||||
FMT_MAKE_VALUE(cstring_type, signed char*, const signed char*)
|
FMT_MAKE_VALUE(cstring_type, signed char*, const signed char*)
|
||||||
FMT_MAKE_VALUE(cstring_type, const signed char*, const signed char*)
|
FMT_MAKE_VALUE(cstring_type, const signed char*, const signed char*)
|
||||||
FMT_MAKE_VALUE(cstring_type, unsigned char*, const unsigned char*)
|
FMT_MAKE_VALUE(cstring_type, unsigned char*, const unsigned char*)
|
||||||
FMT_MAKE_VALUE(cstring_type, const unsigned char*, const unsigned char*)
|
FMT_MAKE_VALUE(cstring_type, const unsigned char*, const unsigned char*)
|
||||||
FMT_MAKE_VALUE(string_type, basic_string_view<typename C::char_type>,
|
FMT_MAKE_VALUE(string_type, basic_string_view<typename C::char_type>,
|
||||||
basic_string_view<Char>)
|
basic_string_view<typename C::char_type>)
|
||||||
FMT_MAKE_VALUE(string_type,
|
FMT_MAKE_VALUE(string_type,
|
||||||
typename basic_string_view<typename C::char_type>::type,
|
typename basic_string_view<typename C::char_type>::type,
|
||||||
basic_string_view<Char>)
|
basic_string_view<typename C::char_type>)
|
||||||
FMT_MAKE_VALUE(string_type, const std::basic_string<typename C::char_type>&,
|
FMT_MAKE_VALUE(string_type, const std::basic_string<typename C::char_type>&,
|
||||||
basic_string_view<Char>)
|
basic_string_view<typename C::char_type>)
|
||||||
FMT_MAKE_VALUE(pointer_type, void*, const void*)
|
FMT_MAKE_VALUE(pointer_type, void*, const void*)
|
||||||
FMT_MAKE_VALUE(pointer_type, const void*, const void*)
|
FMT_MAKE_VALUE(pointer_type, const void*, const void*)
|
||||||
|
|
||||||
|
@ -47,22 +47,12 @@ endfunction ()
|
|||||||
# check if the source file skeleton compiles
|
# check if the source file skeleton compiles
|
||||||
expect_compile("")
|
expect_compile("")
|
||||||
|
|
||||||
# MakeArg doesn't accept [const] volatile char *.
|
|
||||||
expect_compile_error("volatile char s[] = \"test\"; (fmt::internal::MakeArg<char>)(s);")
|
|
||||||
expect_compile_error("const volatile char s[] = \"test\"; (fmt::internal::MakeArg<char>)(s);")
|
|
||||||
|
|
||||||
# MakeArg<char> doesn't accept wchar_t.
|
|
||||||
expect_compile_error("fmt::internal::MakeValue<char>(L'a');")
|
|
||||||
expect_compile_error("fmt::internal::MakeValue<char>(L\"test\");")
|
|
||||||
|
|
||||||
# Writing a wide character to a character stream Writer is forbidden.
|
|
||||||
expect_compile_error("fmt::MemoryWriter() << L'a';")
|
|
||||||
expect_compile_error("fmt::MemoryWriter() << fmt::pad(\"abc\", 5, L' ');")
|
|
||||||
expect_compile_error("fmt::MemoryWriter() << fmt::pad(42, 5, L' ');")
|
|
||||||
|
|
||||||
# Formatting a wide character with a narrow format string is forbidden.
|
# Formatting a wide character with a narrow format string is forbidden.
|
||||||
expect_compile_error("fmt::format(\"{}\", L'a';")
|
expect_compile_error("fmt::format(\"{}\", L'a';")
|
||||||
|
|
||||||
|
# Formatting a wide string with a narrow format string is forbidden.
|
||||||
|
expect_compile_error("fmt::format(\"{}\", L\"foo\";")
|
||||||
|
|
||||||
# Make sure that compiler features detected in the header
|
# Make sure that compiler features detected in the header
|
||||||
# match the features detected in CMake.
|
# match the features detected in CMake.
|
||||||
if (SUPPORTS_USER_DEFINED_LITERALS)
|
if (SUPPORTS_USER_DEFINED_LITERALS)
|
||||||
|
Loading…
Reference in New Issue
Block a user