Avoid MSVC warning about correctly default-initializing arrays

Don't rely on default array initialization, not only it may not work
with some really old compilers (which is actually not that important as
we don't seem to rely on these arrays being initialized, in fact), but
it results in warnings about working correctly (sic) from MSVC in
versions from 9 up to 12 inclusive.

See https://github.com/wxWidgets/wxWidgets/pull/467#issuecomment-310193867
This commit is contained in:
Vadim Zeitlin
2017-06-22 01:47:59 +02:00
parent 16252f1299
commit 4d3aaafc86

View File

@@ -48,7 +48,15 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
// encodes the characters as UTF-16:
struct Utf16CharBuffer
{
Utf16CharBuffer() : data() {}
Utf16CharBuffer()
{
// Can't rely on default initialization of the member array, it
// doesn't work at all in very old compilers and works, but warns
// about working correctly (!) in even recent versions of MSVC
// (warning C4351), so do it manually.
data[0] = 0;
}
wchar_t data[3];
operator const wchar_t*() const { return data; }
};
@@ -61,7 +69,12 @@ struct WXDLLIMPEXP_BASE wxStringOperationsWchar
// representation
struct SingleCharBuffer
{
SingleCharBuffer() : data() {}
SingleCharBuffer()
{
// See comment above.
data[0] = 0;
}
wxChar data[2];
operator const wxChar*() const { return data; }
};