hopefully finally fixed the problem with ambiguous overloads of wxString::operator[] for _all_ machines
git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@10570 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775
This commit is contained in:
55
configure.in
55
configure.in
@@ -2278,25 +2278,58 @@ AC_CACHE_CHECK([for wchar_t], wx_cv_type_wchar_t,
|
|||||||
[
|
[
|
||||||
AC_TRY_COMPILE([#include <wchar.h>],
|
AC_TRY_COMPILE([#include <wchar.h>],
|
||||||
[
|
[
|
||||||
wchar_t wc, *ws;
|
wchar_t wc, *ws;
|
||||||
wc = L'a';
|
wc = L'a';
|
||||||
ws = L"Hello, world!";
|
ws = L"Hello, world!";
|
||||||
],
|
],
|
||||||
wx_cv_type_wchar_t=yes,
|
wx_cv_type_wchar_t=yes,
|
||||||
AC_TRY_COMPILE([#include <stdlib.h>],
|
AC_TRY_COMPILE([#include <stdlib.h>],
|
||||||
[
|
[
|
||||||
wchar_t wc, *ws;
|
wchar_t wc, *ws;
|
||||||
wc = L'a';
|
wc = L'a';
|
||||||
ws = L"Hello, world!";
|
ws = L"Hello, world!";
|
||||||
],
|
],
|
||||||
wx_cv_type_wchar_t=yes,
|
wx_cv_type_wchar_t=yes,
|
||||||
wx_cv_type_wchar_t=no)
|
wx_cv_type_wchar_t=no)
|
||||||
)
|
)
|
||||||
])
|
])
|
||||||
if test "$wx_cv_type_wchar_t" = yes ; then
|
|
||||||
|
if test "$wx_cv_type_wchar_t" = "yes"; then
|
||||||
AC_DEFINE(wxUSE_WCHAR_T)
|
AC_DEFINE(wxUSE_WCHAR_T)
|
||||||
fi
|
fi
|
||||||
|
|
||||||
|
dnl check what exactly size_t is on this machine - this is necessary to avoid
|
||||||
|
dnl ambiguos overloads in several places, notably wx/string.h and wx/array.h
|
||||||
|
AC_CACHE_CHECK([if size_t is unsigned int],
|
||||||
|
wx_cv_size_t_is_uint,
|
||||||
|
AC_TRY_COMPILE([#include <stddef.h>],
|
||||||
|
[
|
||||||
|
struct Foo { void foo(size_t); void foo(unsigned int); };
|
||||||
|
],
|
||||||
|
wx_cv_size_t_is_uint=no,
|
||||||
|
wx_cv_size_t_is_uint=yes
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if test "$wx_cv_size_t_is_uint" = "yes"; then
|
||||||
|
AC_DEFINE(wxSIZE_T_IS_UINT)
|
||||||
|
else
|
||||||
|
AC_CACHE_CHECK([if size_t is unsigned long],
|
||||||
|
wx_cv_size_t_is_ulong,
|
||||||
|
AC_TRY_COMPILE([#include <stddef.h>],
|
||||||
|
[
|
||||||
|
struct Foo { void foo(size_t); void foo(unsigned long); };
|
||||||
|
],
|
||||||
|
wx_cv_size_t_is_ulong=no,
|
||||||
|
wx_cv_size_t_is_ulong=yes
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
|
if test "$wx_cv_size_t_is_ulong" = "yes"; then
|
||||||
|
AC_DEFINE(wxSIZE_T_IS_ULONG)
|
||||||
|
fi
|
||||||
|
fi
|
||||||
|
|
||||||
dnl ---------------------------------------------------------------------------
|
dnl ---------------------------------------------------------------------------
|
||||||
dnl Checks for structures
|
dnl Checks for structures
|
||||||
dnl ---------------------------------------------------------------------------
|
dnl ---------------------------------------------------------------------------
|
||||||
|
@@ -401,6 +401,28 @@ public:
|
|||||||
wxChar& Last()
|
wxChar& Last()
|
||||||
{ wxASSERT( !IsEmpty() ); CopyBeforeWrite(); return m_pchData[Len()-1]; }
|
{ wxASSERT( !IsEmpty() ); CopyBeforeWrite(); return m_pchData[Len()-1]; }
|
||||||
|
|
||||||
|
/*
|
||||||
|
So why do we have all these overloaded operator[]s? A bit of history:
|
||||||
|
initially there was only one of them, taking size_t. Then people
|
||||||
|
started complaining because they wanted to use ints as indices (I
|
||||||
|
wonder why) and compilers were giving warnings about it, so we had to
|
||||||
|
add the operator[](int). Then it became apparent that you couldn't
|
||||||
|
write str[0] any longer because there was ambiguity between two
|
||||||
|
overloads and so you now had to write str[0u] (or, of course, use the
|
||||||
|
explicit casts to either int or size_t but nobody did this).
|
||||||
|
|
||||||
|
Finally, someone decided to compile wxWin on an Alpha machine and got
|
||||||
|
a surprize: str[0u] didn't compile there because it is of type
|
||||||
|
unsigned int and size_t is unsigned _long_ on Alpha and so there was
|
||||||
|
ambiguity between converting uint to int or ulong. To fix this one we
|
||||||
|
now add operator[](uint) for the machines where size_t is not already
|
||||||
|
the same as unsigned int - hopefully this fixes the problem (for some
|
||||||
|
time)
|
||||||
|
|
||||||
|
The only real fix is, of course, to remove all versions but the one
|
||||||
|
taking size_t...
|
||||||
|
*/
|
||||||
|
|
||||||
// operator version of GetChar
|
// operator version of GetChar
|
||||||
wxChar operator[](size_t n) const
|
wxChar operator[](size_t n) const
|
||||||
{ ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
|
{ ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
|
||||||
@@ -408,20 +430,20 @@ public:
|
|||||||
// operator version of GetChar
|
// operator version of GetChar
|
||||||
wxChar operator[](int n) const
|
wxChar operator[](int n) const
|
||||||
{ ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
|
{ ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
|
||||||
#ifdef __alpha__
|
|
||||||
// operator version of GetChar
|
|
||||||
wxChar operator[](unsigned int n) const
|
|
||||||
{ ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// operator version of GetWriteableChar
|
// operator version of GetWriteableChar
|
||||||
wxChar& operator[](size_t n)
|
wxChar& operator[](size_t n)
|
||||||
{ ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
|
{ ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
|
||||||
#ifdef __alpha__
|
|
||||||
|
#ifndef wxSIZE_T_IS_UINT
|
||||||
|
// operator version of GetChar
|
||||||
|
wxChar operator[](unsigned int n) const
|
||||||
|
{ ASSERT_VALID_INDEX( n ); return m_pchData[n]; }
|
||||||
|
|
||||||
// operator version of GetWriteableChar
|
// operator version of GetWriteableChar
|
||||||
wxChar& operator[](unsigned int n)
|
wxChar& operator[](unsigned int n)
|
||||||
{ ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
|
{ ASSERT_VALID_INDEX( n ); CopyBeforeWrite(); return m_pchData[n]; }
|
||||||
#endif
|
#endif // size_t != unsigned int
|
||||||
|
|
||||||
// implicit conversion to C string
|
// implicit conversion to C string
|
||||||
operator const wxChar*() const { return m_pchData; }
|
operator const wxChar*() const { return m_pchData; }
|
||||||
|
@@ -757,6 +757,12 @@
|
|||||||
/* The number of bytes in a short. */
|
/* The number of bytes in a short. */
|
||||||
#undef SIZEOF_SHORT
|
#undef SIZEOF_SHORT
|
||||||
|
|
||||||
|
/* Define if size_t on your machine is the same type as unsigned int. */
|
||||||
|
#undef wxSIZE_T_IS_UINT
|
||||||
|
|
||||||
|
/* Define if size_t on your machine is the same type as unsigned long. */
|
||||||
|
#undef wxSIZE_T_IS_ULONG
|
||||||
|
|
||||||
/* Define if you have the dlopen function. */
|
/* Define if you have the dlopen function. */
|
||||||
#undef HAVE_DLOPEN
|
#undef HAVE_DLOPEN
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user