mirror of
https://github.com/fmtlib/fmt.git
synced 2024-12-25 07:41:07 +00:00
Disallow formatting of wide strings when using a narrow string formatter.
This commit is contained in:
parent
270ed1cb92
commit
144e1fbb7c
9
format.h
9
format.h
@ -361,7 +361,10 @@ class CharTraits<char> : public BasicCharTraits<char> {
|
||||
// Conversion from wchar_t to char is not allowed.
|
||||
static char ConvertChar(wchar_t);
|
||||
|
||||
public:
|
||||
// Conversion from const wchar_t * to const char * is not allowed.
|
||||
static const wchar_t *check(const wchar_t *s);
|
||||
|
||||
public:
|
||||
typedef const wchar_t *UnsupportedStrType;
|
||||
|
||||
static char ConvertChar(char value) { return value; }
|
||||
@ -386,6 +389,8 @@ class CharTraits<wchar_t> : public BasicCharTraits<wchar_t> {
|
||||
|
||||
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>
|
||||
static int FormatFloat(wchar_t *buffer, std::size_t size,
|
||||
const wchar_t *format, unsigned width, int precision, T value);
|
||||
@ -636,7 +641,7 @@ class MakeArg : public Arg {
|
||||
|
||||
void SetString(WStringRef str) {
|
||||
type = WSTRING;
|
||||
wstring.value = str.c_str();
|
||||
wstring.value = CharTraits<Char>::check(str.c_str());
|
||||
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.
|
||||
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.
|
||||
expect_compile_error("fmt::Writer() << L'a';")
|
||||
|
Loading…
Reference in New Issue
Block a user