Add support for wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR to wxString

This symbol is similar to the existing wxNO_IMPLICIT_WXSTRING_ENCODING
and can be defined when building the application (as opposed to when
building the library) to disable implicit wxString conversions to
pointer types, i.e. char*, wchat_t* and void*.

This makes the just added wxUSE_CHAR_CONV_IN_WXSTRING library build
option unnecessary, so remove it.
This commit is contained in:
Vadim Zeitlin 2023-04-16 01:08:11 +02:00
parent 4913857ef7
commit 889845fbc4
16 changed files with 44 additions and 141 deletions

View file

@ -90,7 +90,6 @@ wx_dependent_option(wxUSE_UTF8_LOCALE_ONLY "only support UTF-8 locales in UTF-8
if(NOT WIN32) if(NOT WIN32)
wx_option(wxUSE_VISIBILITY "use of ELF symbols visibility") wx_option(wxUSE_VISIBILITY "use of ELF symbols visibility")
endif() endif()
wx_option(wxUSE_CHAR_CONV_IN_WXSTRING "provide implicit conversions to const wchar_t* and const char* in wxString" ON)
wx_option(wxUSE_STD_STRING_CONV_IN_WXSTRING "provide implicit conversions to std::wstring and std::string in wxString" OFF) wx_option(wxUSE_STD_STRING_CONV_IN_WXSTRING "provide implicit conversions to std::wstring and std::string in wxString" OFF)
wx_option(wxUSE_UNSAFE_WXSTRING_CONV "provide unsafe implicit conversions in wxString to const char* or std::string") wx_option(wxUSE_UNSAFE_WXSTRING_CONV "provide unsafe implicit conversions in wxString to const char* or std::string")
wx_option(wxUSE_REPRODUCIBLE_BUILD "enable reproducable build" OFF) wx_option(wxUSE_REPRODUCIBLE_BUILD "enable reproducable build" OFF)

View file

@ -159,8 +159,6 @@
#cmakedefine01 wxUSE_UNSAFE_WXSTRING_CONV #cmakedefine01 wxUSE_UNSAFE_WXSTRING_CONV
#cmakedefine01 wxUSE_CHAR_CONV_IN_WXSTRING
#cmakedefine01 wxUSE_STD_STRING_CONV_IN_WXSTRING #cmakedefine01 wxUSE_STD_STRING_CONV_IN_WXSTRING

36
configure vendored
View file

@ -1122,7 +1122,6 @@ with_cxx
enable_stl enable_stl
enable_std_containers enable_std_containers
enable_std_iostreams enable_std_iostreams
enable_char_conv_in_wxstring
enable_std_string_conv_in_wxstring enable_std_string_conv_in_wxstring
enable_unsafe_conv_in_wxstring enable_unsafe_conv_in_wxstring
enable_utf8 enable_utf8
@ -2089,7 +2088,6 @@ Optional Features:
--enable-stl obsolete option doing nothing --enable-stl obsolete option doing nothing
--disable-std_containers disable use of standard C++ container classes --disable-std_containers disable use of standard C++ container classes
--disable-std_iostreams disable use of standard C++ stream classes --disable-std_iostreams disable use of standard C++ stream classes
--disable-char_conv_in_wxstring disable implicit conversion to const wchar_t/char* in wxString
--enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString
--disable-unsafe_conv_in_wxstring disable unsafe implicit conversions in wxString --disable-unsafe_conv_in_wxstring disable unsafe implicit conversions in wxString
--enable-utf8 use UTF-8 representation for strings --enable-utf8 use UTF-8 representation for strings
@ -5637,35 +5635,6 @@ fi
eval "$wx_cv_use_std_iostreams" eval "$wx_cv_use_std_iostreams"
enablestring=disable
defaultval=
if test -z "$defaultval"; then
if test x"$enablestring" = xdisable; then
defaultval=yes
else
defaultval=no
fi
fi
# Check whether --enable-char_conv_in_wxstring was given.
if test "${enable_char_conv_in_wxstring+set}" = set; then :
enableval=$enable_char_conv_in_wxstring;
if test "$enableval" = yes; then
wx_cv_use_char_conv_in_wxstring='wxUSE_CHAR_CONV_IN_WXSTRING=yes'
else
wx_cv_use_char_conv_in_wxstring='wxUSE_CHAR_CONV_IN_WXSTRING=no'
fi
else
wx_cv_use_char_conv_in_wxstring='wxUSE_CHAR_CONV_IN_WXSTRING=${'DEFAULT_wxUSE_CHAR_CONV_IN_WXSTRING":-$defaultval}"
fi
eval "$wx_cv_use_char_conv_in_wxstring"
enablestring= enablestring=
defaultval= defaultval=
if test -z "$defaultval"; then if test -z "$defaultval"; then
@ -37464,11 +37433,6 @@ if test "$wxUSE_STD_IOSTREAM" = "yes"; then
fi fi
if test "$wxUSE_CHAR_CONV_IN_WXSTRING" = "yes"; then
$as_echo "#define wxUSE_CHAR_CONV_IN_WXSTRING 1" >>confdefs.h
fi
if test "$wxUSE_STD_STRING_CONV_IN_WXSTRING" = "yes"; then if test "$wxUSE_STD_STRING_CONV_IN_WXSTRING" = "yes"; then
$as_echo "#define wxUSE_STD_STRING_CONV_IN_WXSTRING 1" >>confdefs.h $as_echo "#define wxUSE_STD_STRING_CONV_IN_WXSTRING 1" >>confdefs.h

View file

@ -642,7 +642,6 @@ AC_ARG_WITH(cxx, [ --with-cxx=11|14|17|20 use the given C++ dialect]
WX_ARG_ENABLE(stl, [ --enable-stl obsolete option doing nothing], wxUSE_STL) WX_ARG_ENABLE(stl, [ --enable-stl obsolete option doing nothing], wxUSE_STL)
WX_ARG_DISABLE(std_containers,[ --disable-std_containers disable use of standard C++ container classes], wxUSE_STD_CONTAINERS) WX_ARG_DISABLE(std_containers,[ --disable-std_containers disable use of standard C++ container classes], wxUSE_STD_CONTAINERS)
WX_ARG_DISABLE(std_iostreams,[ --disable-std_iostreams disable use of standard C++ stream classes], wxUSE_STD_IOSTREAM) WX_ARG_DISABLE(std_iostreams,[ --disable-std_iostreams disable use of standard C++ stream classes], wxUSE_STD_IOSTREAM)
WX_ARG_DISABLE(char_conv_in_wxstring, [ --disable-char_conv_in_wxstring disable implicit conversion to const wchar_t/char* in wxString], wxUSE_CHAR_CONV_IN_WXSTRING)
WX_ARG_ENABLE(std_string_conv_in_wxstring, [ --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString], wxUSE_STD_STRING_CONV_IN_WXSTRING) WX_ARG_ENABLE(std_string_conv_in_wxstring, [ --enable-std_string_conv_in_wxstring provide implicit conversion to std::string in wxString], wxUSE_STD_STRING_CONV_IN_WXSTRING)
WX_ARG_DISABLE(unsafe_conv_in_wxstring, [ --disable-unsafe_conv_in_wxstring disable unsafe implicit conversions in wxString], wxUSE_UNSAFE_WXSTRING_CONV) WX_ARG_DISABLE(unsafe_conv_in_wxstring, [ --disable-unsafe_conv_in_wxstring disable unsafe implicit conversions in wxString], wxUSE_UNSAFE_WXSTRING_CONV)
WX_ARG_ENABLE_PARAM(utf8, [ --enable-utf8 use UTF-8 representation for strings], wxUSE_UNICODE_UTF8) WX_ARG_ENABLE_PARAM(utf8, [ --enable-utf8 use UTF-8 representation for strings], wxUSE_UNICODE_UTF8)
@ -5391,10 +5390,6 @@ if test "$wxUSE_STD_IOSTREAM" = "yes"; then
AC_DEFINE(wxUSE_STD_IOSTREAM) AC_DEFINE(wxUSE_STD_IOSTREAM)
fi fi
if test "$wxUSE_CHAR_CONV_IN_WXSTRING" = "yes"; then
AC_DEFINE(wxUSE_CHAR_CONV_IN_WXSTRING)
fi
if test "$wxUSE_STD_STRING_CONV_IN_WXSTRING" = "yes"; then if test "$wxUSE_STD_STRING_CONV_IN_WXSTRING" = "yes"; then
AC_DEFINE(wxUSE_STD_STRING_CONV_IN_WXSTRING) AC_DEFINE(wxUSE_STD_STRING_CONV_IN_WXSTRING)
fi fi

View file

@ -43,7 +43,7 @@ library:
available.} available.}
@itemdef{wxUSE_UNSAFE_WXSTRING_CONV, Defined as 1 by default for compatibility, @itemdef{wxUSE_UNSAFE_WXSTRING_CONV, Defined as 1 by default for compatibility,
but can be set to 0 to globally disable unsafe implicit conversions in but can be set to 0 to globally disable unsafe implicit conversions in
wxString class. See @ref overview_string_settings for more details.} wxString class. See @ref string_conv for more details.}
@endDefList @endDefList

View file

@ -284,7 +284,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Provide unsafe implicit conversions in wxString to "const char*" or // Provide unsafe implicit conversions in wxString to "const char*" or
// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). // "std::string" (only if implicit conversions are not disabled entirely).
// //
// Default is 1 for compatibility reasons, it is recommended to set // Default is 1 for compatibility reasons, it is recommended to set
// this to 0 because converting wxString to a narrow (non-Unicode) string may // this to 0 because converting wxString to a narrow (non-Unicode) string may
@ -297,16 +297,6 @@
// application code to effectively disallow using these conversions. // application code to effectively disallow using these conversions.
#define wxUSE_UNSAFE_WXSTRING_CONV 1 #define wxUSE_UNSAFE_WXSTRING_CONV 1
// Define implicit conversions of wxString to "const wchar_t*" and "const
// char*" if wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
//
// Default is 1.
//
// Recommended setting: 1 to remain compatible with the official builds of
// wxWidgets but may be set to 0 to prevent any accidental conversions from
// happening.
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
// Define implicit conversions of wxString to std::wstring and std::string if // Define implicit conversions of wxString to std::wstring and std::string if
// wxUSE_UNSAFE_WXSTRING_CONV is also enabled. // wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
// //
@ -314,9 +304,9 @@
// this option is turned on or off, it only enables implicit conversion in the // this option is turned on or off, it only enables implicit conversion in the
// other direction. // other direction.
// //
// If this setting is changed to 1, wxUSE_CHAR_CONV_IN_WXSTRING must be set to // If this setting is changed to 1, implicit conversions to pointer types are
// 0 as setting both of them to 1 will result in ambiguities due to having too // disabled as defining both kinds of implicit conversions would result in
// many implicit conversions defined. // ambiguities.
// //
// Default is 0. // Default is 0.
// //

View file

@ -285,7 +285,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Provide unsafe implicit conversions in wxString to "const char*" or // Provide unsafe implicit conversions in wxString to "const char*" or
// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). // "std::string" (only if implicit conversions are not disabled entirely).
// //
// Default is 1 for compatibility reasons, it is recommended to set // Default is 1 for compatibility reasons, it is recommended to set
// this to 0 because converting wxString to a narrow (non-Unicode) string may // this to 0 because converting wxString to a narrow (non-Unicode) string may
@ -298,16 +298,6 @@
// application code to effectively disallow using these conversions. // application code to effectively disallow using these conversions.
#define wxUSE_UNSAFE_WXSTRING_CONV 1 #define wxUSE_UNSAFE_WXSTRING_CONV 1
// Define implicit conversions of wxString to "const wchar_t*" and "const
// char*" if wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
//
// Default is 1.
//
// Recommended setting: 1 to remain compatible with the official builds of
// wxWidgets but may be set to 0 to prevent any accidental conversions from
// happening.
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
// Define implicit conversions of wxString to std::wstring and std::string if // Define implicit conversions of wxString to std::wstring and std::string if
// wxUSE_UNSAFE_WXSTRING_CONV is also enabled. // wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
// //
@ -315,9 +305,9 @@
// this option is turned on or off, it only enables implicit conversion in the // this option is turned on or off, it only enables implicit conversion in the
// other direction. // other direction.
// //
// If this setting is changed to 1, wxUSE_CHAR_CONV_IN_WXSTRING must be set to // If this setting is changed to 1, implicit conversions to pointer types are
// 0 as setting both of them to 1 will result in ambiguities due to having too // disabled as defining both kinds of implicit conversions would result in
// many implicit conversions defined. // ambiguities.
// //
// Default is 0. // Default is 0.
// //

View file

@ -285,7 +285,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Provide unsafe implicit conversions in wxString to "const char*" or // Provide unsafe implicit conversions in wxString to "const char*" or
// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). // "std::string" (only if implicit conversions are not disabled entirely).
// //
// Default is 1 for compatibility reasons, it is recommended to set // Default is 1 for compatibility reasons, it is recommended to set
// this to 0 because converting wxString to a narrow (non-Unicode) string may // this to 0 because converting wxString to a narrow (non-Unicode) string may
@ -298,16 +298,6 @@
// application code to effectively disallow using these conversions. // application code to effectively disallow using these conversions.
#define wxUSE_UNSAFE_WXSTRING_CONV 1 #define wxUSE_UNSAFE_WXSTRING_CONV 1
// Define implicit conversions of wxString to "const wchar_t*" and "const
// char*" if wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
//
// Default is 1.
//
// Recommended setting: 1 to remain compatible with the official builds of
// wxWidgets but may be set to 0 to prevent any accidental conversions from
// happening.
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
// Define implicit conversions of wxString to std::wstring and std::string if // Define implicit conversions of wxString to std::wstring and std::string if
// wxUSE_UNSAFE_WXSTRING_CONV is also enabled. // wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
// //
@ -315,9 +305,9 @@
// this option is turned on or off, it only enables implicit conversion in the // this option is turned on or off, it only enables implicit conversion in the
// other direction. // other direction.
// //
// If this setting is changed to 1, wxUSE_CHAR_CONV_IN_WXSTRING must be set to // If this setting is changed to 1, implicit conversions to pointer types are
// 0 as setting both of them to 1 will result in ambiguities due to having too // disabled as defining both kinds of implicit conversions would result in
// many implicit conversions defined. // ambiguities.
// //
// Default is 0. // Default is 0.
// //

View file

@ -291,7 +291,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Provide unsafe implicit conversions in wxString to "const char*" or // Provide unsafe implicit conversions in wxString to "const char*" or
// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). // "std::string" (only if implicit conversions are not disabled entirely).
// //
// Default is 1 for compatibility reasons, it is recommended to set // Default is 1 for compatibility reasons, it is recommended to set
// this to 0 because converting wxString to a narrow (non-Unicode) string may // this to 0 because converting wxString to a narrow (non-Unicode) string may
@ -304,16 +304,6 @@
// application code to effectively disallow using these conversions. // application code to effectively disallow using these conversions.
#define wxUSE_UNSAFE_WXSTRING_CONV 1 #define wxUSE_UNSAFE_WXSTRING_CONV 1
// Define implicit conversions of wxString to "const wchar_t*" and "const
// char*" if wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
//
// Default is 1.
//
// Recommended setting: 1 to remain compatible with the official builds of
// wxWidgets but may be set to 0 to prevent any accidental conversions from
// happening.
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
// Define implicit conversions of wxString to std::wstring and std::string if // Define implicit conversions of wxString to std::wstring and std::string if
// wxUSE_UNSAFE_WXSTRING_CONV is also enabled. // wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
// //
@ -321,9 +311,9 @@
// this option is turned on or off, it only enables implicit conversion in the // this option is turned on or off, it only enables implicit conversion in the
// other direction. // other direction.
// //
// If this setting is changed to 1, wxUSE_CHAR_CONV_IN_WXSTRING must be set to // If this setting is changed to 1, implicit conversions to pointer types are
// 0 as setting both of them to 1 will result in ambiguities due to having too // disabled as defining both kinds of implicit conversions would result in
// many implicit conversions defined. // ambiguities.
// //
// Default is 0. // Default is 0.
// //

View file

@ -281,7 +281,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Provide unsafe implicit conversions in wxString to "const char*" or // Provide unsafe implicit conversions in wxString to "const char*" or
// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). // "std::string" (only if implicit conversions are not disabled entirely).
// //
// Default is 1 for compatibility reasons, it is recommended to set // Default is 1 for compatibility reasons, it is recommended to set
// this to 0 because converting wxString to a narrow (non-Unicode) string may // this to 0 because converting wxString to a narrow (non-Unicode) string may
@ -294,16 +294,6 @@
// application code to effectively disallow using these conversions. // application code to effectively disallow using these conversions.
#define wxUSE_UNSAFE_WXSTRING_CONV 1 #define wxUSE_UNSAFE_WXSTRING_CONV 1
// Define implicit conversions of wxString to "const wchar_t*" and "const
// char*" if wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
//
// Default is 1.
//
// Recommended setting: 1 to remain compatible with the official builds of
// wxWidgets but may be set to 0 to prevent any accidental conversions from
// happening.
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
// Define implicit conversions of wxString to std::wstring and std::string if // Define implicit conversions of wxString to std::wstring and std::string if
// wxUSE_UNSAFE_WXSTRING_CONV is also enabled. // wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
// //
@ -311,9 +301,9 @@
// this option is turned on or off, it only enables implicit conversion in the // this option is turned on or off, it only enables implicit conversion in the
// other direction. // other direction.
// //
// If this setting is changed to 1, wxUSE_CHAR_CONV_IN_WXSTRING must be set to // If this setting is changed to 1, implicit conversions to pointer types are
// 0 as setting both of them to 1 will result in ambiguities due to having too // disabled as defining both kinds of implicit conversions would result in
// many implicit conversions defined. // ambiguities.
// //
// Default is 0. // Default is 0.
// //

View file

@ -98,6 +98,14 @@ class WXDLLIMPEXP_FWD_BASE wxString;
#endif #endif
#endif // wxUSE_UNSAFE_WXSTRING_CONV #endif // wxUSE_UNSAFE_WXSTRING_CONV
// enabling implicit conversions to std::[w]string is incompatible with having
// implicit conversions to char*/wchar_t*.
#if wxUSE_STD_STRING_CONV_IN_WXSTRING
#ifndef wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR
#define wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR
#endif
#endif // wxUSE_STD_STRING_CONV_IN_WXSTRING
namespace wxPrivate namespace wxPrivate
{ {
template <typename T> struct wxStringAsBufHelper; template <typename T> struct wxStringAsBufHelper;
@ -1540,7 +1548,7 @@ public:
// implicit conversion to wxCStrData // implicit conversion to wxCStrData
operator wxCStrData() const { return c_str(); } operator wxCStrData() const { return c_str(); }
#if wxUSE_CHAR_CONV_IN_WXSTRING #if !defined(wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR)
operator const wchar_t*() const { return c_str(); } operator const wchar_t*() const { return c_str(); }
#if !defined(wxNO_UNSAFE_WXSTRING_CONV) #if !defined(wxNO_UNSAFE_WXSTRING_CONV)
@ -1551,7 +1559,7 @@ public:
operator const void*() const { return c_str(); } operator const void*() const { return c_str(); }
#endif // !defined(wxNO_UNSAFE_WXSTRING_CONV) #endif // !defined(wxNO_UNSAFE_WXSTRING_CONV)
#endif // wxUSE_CHAR_CONV_IN_WXSTRING #endif // !defined(wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR)
// identical to c_str(), for MFC compatibility // identical to c_str(), for MFC compatibility
const wxCStrData GetData() const { return c_str(); } const wxCStrData GetData() const { return c_str(); }

View file

@ -284,7 +284,7 @@
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Provide unsafe implicit conversions in wxString to "const char*" or // Provide unsafe implicit conversions in wxString to "const char*" or
// "std::string" (depending on wxUSE_STD_STRING_CONV_IN_WXSTRING value). // "std::string" (only if implicit conversions are not disabled entirely).
// //
// Default is 1 for compatibility reasons, it is recommended to set // Default is 1 for compatibility reasons, it is recommended to set
// this to 0 because converting wxString to a narrow (non-Unicode) string may // this to 0 because converting wxString to a narrow (non-Unicode) string may
@ -297,16 +297,6 @@
// application code to effectively disallow using these conversions. // application code to effectively disallow using these conversions.
#define wxUSE_UNSAFE_WXSTRING_CONV 1 #define wxUSE_UNSAFE_WXSTRING_CONV 1
// Define implicit conversions of wxString to "const wchar_t*" and "const
// char*" if wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
//
// Default is 1.
//
// Recommended setting: 1 to remain compatible with the official builds of
// wxWidgets but may be set to 0 to prevent any accidental conversions from
// happening.
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
// Define implicit conversions of wxString to std::wstring and std::string if // Define implicit conversions of wxString to std::wstring and std::string if
// wxUSE_UNSAFE_WXSTRING_CONV is also enabled. // wxUSE_UNSAFE_WXSTRING_CONV is also enabled.
// //
@ -314,9 +304,9 @@
// this option is turned on or off, it only enables implicit conversion in the // this option is turned on or off, it only enables implicit conversion in the
// other direction. // other direction.
// //
// If this setting is changed to 1, wxUSE_CHAR_CONV_IN_WXSTRING must be set to // If this setting is changed to 1, implicit conversions to pointer types are
// 0 as setting both of them to 1 will result in ambiguities due to having too // disabled as defining both kinds of implicit conversions would result in
// many implicit conversions defined. // ambiguities.
// //
// Default is 0. // Default is 0.
// //

View file

@ -139,17 +139,20 @@
becomes unavailable -- but explicit conversions using c_str() and mb_str() becomes unavailable -- but explicit conversions using c_str() and mb_str()
still work. still work.
Finally, please note that implicit conversion to both `const char*` and Finally, please note that implicit conversion to both `const char*` (which
`const wchar_t*` may be entirely disabled by setting the build option is unsafe for the reasons explained above) and to `const wchar_t*` (which
`wxUSE_CHAR_CONV_IN_WXSTRING` to 0. Unlike with `wxNO_XXX` constants, this is safe from this point of view, but may still be considered dangerous, as
option requires rebuilding the library after changing its value. any implicit conversion) may be entirely disabled by defining
`wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR` when building the application.
To summarize, the safest way to use wxString is to always define To summarize, the safest way to use wxString is to always define
`wxNO_IMPLICIT_WXSTRING_ENCODING` in the application compilation options to `wxNO_IMPLICIT_WXSTRING_ENCODING` in the application compilation options to
disable all implicit uses of encoding and specify it explicitly, typically disable all implicit uses of encoding and specify it explicitly, typically
by using utf8_str() or utf8_string() and FromUTF8() for conversions, for by using utf8_str() or utf8_string() and FromUTF8() for conversions, for
every operation. every operation. If this is impossible, for example because it would
require too many changes to the existing code, consider defining
`wxNO_UNSAFE_WXSTRING_CONV` to at least disable implicit unsafe conversions.
@section string_gotchas Traps for the unwary @section string_gotchas Traps for the unwary

View file

@ -162,8 +162,6 @@
#define wxUSE_UNSAFE_WXSTRING_CONV 0 #define wxUSE_UNSAFE_WXSTRING_CONV 0
#define wxUSE_CHAR_CONV_IN_WXSTRING 0
#define wxUSE_STD_STRING_CONV_IN_WXSTRING 0 #define wxUSE_STD_STRING_CONV_IN_WXSTRING 0

View file

@ -195,8 +195,6 @@ typedef pid_t GPid;
#define wxUSE_STD_CONTAINERS 0 #define wxUSE_STD_CONTAINERS 0
#define wxUSE_CHAR_CONV_IN_WXSTRING 1
#define wxUSE_STD_STRING_CONV_IN_WXSTRING 0 #define wxUSE_STD_STRING_CONV_IN_WXSTRING 0
#define wxUSE_LONGLONG 1 #define wxUSE_LONGLONG 1

View file

@ -1018,7 +1018,7 @@ TEST_CASE("StringCStrDataImplicitConversion", "[wxString]")
CHECK( CheckStrConstWChar(s, s.c_str()) ); CHECK( CheckStrConstWChar(s, s.c_str()) );
CHECK( CheckStrConstChar(s, s.c_str()) ); CHECK( CheckStrConstChar(s, s.c_str()) );
#if wxUSE_CHAR_CONV_IN_WXSTRING #ifndef wxNO_IMPLICIT_WXSTRING_CONV_TO_PTR
CHECK( CheckStrConstWChar(s, s) ); CHECK( CheckStrConstWChar(s, s) );
#ifndef wxNO_UNSAFE_WXSTRING_CONV #ifndef wxNO_UNSAFE_WXSTRING_CONV
CHECK( CheckStrConstChar(s, s) ); CHECK( CheckStrConstChar(s, s) );