]> git.saurik.com Git - wxWidgets.git/commitdiff
remove implicit conversion to C strings from wxString if wxUSE_STL=1; this fixes...
authorVáclav Slavík <vslavik@fastmail.fm>
Wed, 20 Jun 2007 07:47:51 +0000 (07:47 +0000)
committerVáclav Slavík <vslavik@fastmail.fm>
Wed, 20 Jun 2007 07:47:51 +0000 (07:47 +0000)
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@46554 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775

include/wx/string.h
tests/strings/stdstrings.cpp
tests/strings/strings.cpp

index a71591134370b85d0fbab6e332b6ff5179d0f77e..7cccebcad3b9ef04c1002ef088fbb8a79022d4b8 100644 (file)
@@ -1003,7 +1003,12 @@ public:
     wxString(const std::string& str)
         { assign(str.c_str(), str.length()); }
   #endif
+#endif // wxUSE_STD_STRING
 
+  // Unlike ctor from std::string, we provide conversion to std::string only
+  // if wxUSE_STL and not merely wxUSE_STD_STRING (which is on by default),
+  // because it conflicts with operator const char/wchar_t*:
+#if wxUSE_STL
   #if wxUSE_UNICODE_WCHAR && wxUSE_STL_BASED_WXSTRING
     // wxStringImpl is std::string in the encoding we want
     operator const wxStdWideString&() const { return m_impl; }
@@ -1176,8 +1181,13 @@ public:
 
     // implicit conversion to C string
     operator wxCStrData() const { return c_str(); }
+
+    // these operators conflict with operators for conversion to std::string,
+    // so they must be disabled in STL build:
+#if !wxUSE_STL
     operator const char*() const { return c_str(); }
     operator const wchar_t*() const { return c_str(); }
+#endif
 
     // implicit conversion to untyped pointer for compatibility with previous
     // wxWidgets versions: this is the same as conversion to const char * so it
index 9cb81dffe6e40e9641b46ff8f89644bc07b21c2a..3721bf937276c22ed23cbc53cc68e44ae5bff84e 100644 (file)
@@ -1,4 +1,4 @@
-///////////////////////////////////////////////////////////////////////////////
+//////////////////////////////////////////////////////////////////////////////
 // Name:        tests/strings/stdstrings.cpp
 // Purpose:     wxString unit test
 // Author:      Vadim Zeitlin, Wlodzimierz ABX Skiba
@@ -101,7 +101,7 @@ void StdStringTestCase::StdConstructors()
     CPPUNIT_ASSERT( s7 == s1 );
     CPPUNIT_ASSERT( s8 == _T("efgh") );
 
-    const char *pc = s1;
+    const char *pc = s1.c_str();
     WX_ASSERT_STR_EQUAL( "bcd", wxString(pc + 1, pc + 4) );
 
     const wchar_t *pw = s2.c_str();
@@ -165,7 +165,7 @@ void StdStringTestCase::StdAssign()
     CPPUNIT_ASSERT( s5 == _T("aaa") );
     CPPUNIT_ASSERT( s6 == _T("ef") );
 
-    const char *pc = s1;
+    const char *pc = s1.c_str();
     s7.assign(pc, pc + 2);
     WX_ASSERT_STR_EQUAL( "de", s7 );
 
@@ -539,10 +539,21 @@ void StdStringTestCase::StdConversion()
     CPPUNIT_ASSERT( s3 == "std::wstring value" );
 
     wxString s4("hello");
+
+    // wxString -> std::string conversion is only available in wxUSE_STL case,
+    // because it conflicts with conversion to const char*/wchar_t*:
+#if wxUSE_STL
     std::string s5 = s4;
     CPPUNIT_ASSERT( s5 == "hello" );
 
     wxStdWideString s6 = s4;
     CPPUNIT_ASSERT( s6 == "hello" );
+#endif
+
+    std::string s7(s4);
+    CPPUNIT_ASSERT( s7 == "hello" );
+
+    wxStdWideString s8(s4);
+    CPPUNIT_ASSERT( s8 == "hello" );
 }
 #endif // wxUSE_STD_STRING
index c679d4423e13f33857a31e27bb603fd6dfa39083..6cbeba609f0c4a089ac5d71eab19ca0f04679138 100644 (file)
@@ -736,10 +736,13 @@ void StringTestCase::CStrDataImplicitConversion()
     wxString s("foo");
 
     CPPUNIT_ASSERT( CheckStrConstWChar(s, s.c_str()) );
-    CPPUNIT_ASSERT( CheckStrConstWChar(s, s) );
-
     CPPUNIT_ASSERT( CheckStrConstChar(s, s.c_str()) );
+
+    // implicit conversion of wxString is not available in STL build
+#if !wxUSE_STL
+    CPPUNIT_ASSERT( CheckStrConstWChar(s, s) );
     CPPUNIT_ASSERT( CheckStrConstChar(s, s) );
+#endif
 }
 
 void StringTestCase::ExplicitConversion()