From 4913857ef74d2bbc1d4f686c9ce81dcf36abd6b5 Mon Sep 17 00:00:00 2001 From: Vadim Zeitlin Date: Sun, 16 Apr 2023 01:03:51 +0200 Subject: [PATCH] Define wxNO_UNSAFE_WXSTRING_CONV if wxUSE_UNSAFE_WXSTRING_CONV==0 This doesn't really change anything, but allows to simplify the tests, as we can now check only for wxNO_UNSAFE_WXSTRING_CONV and this covers both the case of the library compiled without support for the unsafe conversions at all and the case when the conversions are disabled by explicitly defining wxNO_UNSAFE_WXSTRING_CONV when building the application. --- include/wx/string.h | 16 +++++++++++----- tests/strings/stdstrings.cpp | 4 ++-- tests/strings/strings.cpp | 2 +- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/include/wx/string.h b/include/wx/string.h index 1edfd388ef..0a4d106c0d 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -90,7 +90,13 @@ class WXDLLIMPEXP_FWD_BASE wxString; #error wxNO_IMPLICIT_WXSTRING_ENCODING cannot be used in UTF-8 only builds #endif -#endif +#endif // wxNO_IMPLICIT_WXSTRING_ENCODING + +#if !wxUSE_UNSAFE_WXSTRING_CONV + #ifndef wxNO_UNSAFE_WXSTRING_CONV + #define wxNO_UNSAFE_WXSTRING_CONV + #endif +#endif // wxUSE_UNSAFE_WXSTRING_CONV namespace wxPrivate { @@ -1287,9 +1293,9 @@ public: // they conflict with the implicit conversions to "const char/wchar_t *" // which we use for backwards compatibility but do provide them if // explicitly requested. -#if wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV) +#if !defined(wxNO_UNSAFE_WXSTRING_CONV) operator wxStringToStdStringRetType() const { return ToStdString(); } -#endif // wxUSE_UNSAFE_WXSTRING_CONV +#endif // !wxNO_UNSAFE_WXSTRING_CONV operator wxStringToStdWstringRetType() const { return ToStdWstring(); } #endif // wxUSE_STD_STRING_CONV_IN_WXSTRING @@ -1537,13 +1543,13 @@ public: #if wxUSE_CHAR_CONV_IN_WXSTRING operator const wchar_t*() const { return c_str(); } -#if wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV) +#if !defined(wxNO_UNSAFE_WXSTRING_CONV) operator const char*() const { return c_str(); } // implicit conversion to untyped pointer for compatibility with previous // wxWidgets versions: this is the same as conversion to const char * so it // may fail! operator const void*() const { return c_str(); } -#endif // wxUSE_UNSAFE_WXSTRING_CONV && !defined(wxNO_UNSAFE_WXSTRING_CONV) +#endif // !defined(wxNO_UNSAFE_WXSTRING_CONV) #endif // wxUSE_CHAR_CONV_IN_WXSTRING diff --git a/tests/strings/stdstrings.cpp b/tests/strings/stdstrings.cpp index 9010bcbe87..19f6dd9792 100644 --- a/tests/strings/stdstrings.cpp +++ b/tests/strings/stdstrings.cpp @@ -614,7 +614,7 @@ TEST_CASE("StdString::Conversion", "[stdstring]") wxString s4("hello"); -#if wxUSE_STD_STRING_CONV_IN_WXSTRING && wxUSE_UNSAFE_WXSTRING_CONV +#if wxUSE_STD_STRING_CONV_IN_WXSTRING && !defined(wxNO_UNSAFE_WXSTRING_CONV) std::string s5 = s4; #else std::string s5 = s4.ToStdString(); @@ -629,7 +629,7 @@ TEST_CASE("StdString::Conversion", "[stdstring]") CHECK( s6 == L"hello" ); #if wxUSE_STD_STRING_CONV_IN_WXSTRING -#if wxUSE_UNSAFE_WXSTRING_CONV +#if !defined(wxNO_UNSAFE_WXSTRING_CONV) std::string s7(s4); CHECK( s7 == "hello" ); #endif diff --git a/tests/strings/strings.cpp b/tests/strings/strings.cpp index 5cf68619d0..ed04009097 100644 --- a/tests/strings/strings.cpp +++ b/tests/strings/strings.cpp @@ -1020,7 +1020,7 @@ TEST_CASE("StringCStrDataImplicitConversion", "[wxString]") #if wxUSE_CHAR_CONV_IN_WXSTRING CHECK( CheckStrConstWChar(s, s) ); -#if wxUSE_UNSAFE_WXSTRING_CONV +#ifndef wxNO_UNSAFE_WXSTRING_CONV CHECK( CheckStrConstChar(s, s) ); #endif #endif