mirror of
https://github.com/fmtlib/fmt.git
synced 2024-11-19 11:14:41 +00:00
Disallow formatting of wide strings when using a narrow string formatter.
This commit is contained in:
parent
270ed1cb92
commit
144e1fbb7c
7
format.h
7
format.h
@ -361,6 +361,9 @@ class CharTraits<char> : public BasicCharTraits<char> {
|
|||||||
// Conversion from wchar_t to char is not allowed.
|
// Conversion from wchar_t to char is not allowed.
|
||||||
static char ConvertChar(wchar_t);
|
static char ConvertChar(wchar_t);
|
||||||
|
|
||||||
|
// Conversion from const wchar_t * to const char * is not allowed.
|
||||||
|
static const wchar_t *check(const wchar_t *s);
|
||||||
|
|
||||||
public:
|
public:
|
||||||
typedef const wchar_t *UnsupportedStrType;
|
typedef const wchar_t *UnsupportedStrType;
|
||||||
|
|
||||||
@ -386,6 +389,8 @@ class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
|
|||||||
|
|
||||||
static StringValue<wchar_t> convert(StringValue<wchar_t> s) { return s; }
|
static StringValue<wchar_t> convert(StringValue<wchar_t> s) { return s; }
|
||||||
|
|
||||||
|
static const wchar_t *check(const wchar_t *s) { return s; }
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
static int FormatFloat(wchar_t *buffer, std::size_t size,
|
static int FormatFloat(wchar_t *buffer, std::size_t size,
|
||||||
const wchar_t *format, unsigned width, int precision, T value);
|
const wchar_t *format, unsigned width, int precision, T value);
|
||||||
@ -636,7 +641,7 @@ class MakeArg : public Arg {
|
|||||||
|
|
||||||
void SetString(WStringRef str) {
|
void SetString(WStringRef str) {
|
||||||
type = WSTRING;
|
type = WSTRING;
|
||||||
wstring.value = str.c_str();
|
wstring.value = CharTraits<Char>::check(str.c_str());
|
||||||
wstring.size = str.size();
|
wstring.size = str.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -35,6 +35,7 @@ expect_compile_error("const volatile char s[] = \"test\"; (fmt::internal::MakeAr
|
|||||||
|
|
||||||
# MakeArg<char> doesn't accept wchar_t.
|
# MakeArg<char> doesn't accept wchar_t.
|
||||||
expect_compile_error("fmt::internal::MakeArg<char>(L'a');")
|
expect_compile_error("fmt::internal::MakeArg<char>(L'a');")
|
||||||
|
expect_compile_error("fmt::internal::MakeArg<char>(L\"test\");")
|
||||||
|
|
||||||
# Writing a wide character to a character stream Writer is forbidden.
|
# Writing a wide character to a character stream Writer is forbidden.
|
||||||
expect_compile_error("fmt::Writer() << L'a';")
|
expect_compile_error("fmt::Writer() << L'a';")
|
||||||
|
Loading…
Reference in New Issue
Block a user