From: Vadim Zeitlin Date: Sun, 7 Nov 2010 13:16:20 +0000 (+0000) Subject: Fix build with Borland C++ compiler. X-Git-Url: https://git.saurik.com/wxWidgets.git/commitdiff_plain/258593354e0a19bb74e23d7978fdc01da1942b2a Fix build with Borland C++ compiler. Disable some parts of the code that this compiler had problems with. Add parentheses to work around its bugs elsewhere. Closes #12558. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@66054 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- diff --git a/include/wx/brush.h b/include/wx/brush.h index c3a98ba5eb..89ae912fa1 100644 --- a/include/wx/brush.h +++ b/include/wx/brush.h @@ -119,6 +119,11 @@ extern WXDLLIMPEXP_DATA_CORE(wxBrushList*) wxTheBrushList; // compilers as it compares elements of different enums #if FUTURE_WXWIN_COMPATIBILITY_3_0 +// Unfortunately some compilers have ambiguity issues when enum comparisons are +// overloaded so we have to disable the overloads in this case, see +// wxCOMPILER_NO_OVERLOAD_ON_ENUM definition in wx/platform.h for more details. +#ifndef wxCOMPILER_NO_OVERLOAD_ON_ENUM + inline bool operator==(wxBrushStyle s, wxDeprecatedGUIConstants t) { return static_cast(s) == static_cast(t); @@ -129,6 +134,8 @@ inline bool operator!=(wxBrushStyle s, wxDeprecatedGUIConstants t) return !(s == t); } +#endif // wxCOMPILER_NO_OVERLOAD_ON_ENUM + #endif // FUTURE_WXWIN_COMPATIBILITY_3_0 #endif // _WX_BRUSH_H_BASE_ diff --git a/include/wx/chartype.h b/include/wx/chartype.h index 88b1d5e624..c0658eaf97 100644 --- a/include/wx/chartype.h +++ b/include/wx/chartype.h @@ -238,8 +238,15 @@ #if !wxUSE_UNICODE #define wxT(x) x #else /* Unicode */ - /* use wxCONCAT_HELPER so that x could be expanded if it's a macro */ - #define wxT(x) wxCONCAT_HELPER(L, x) + /* + Notice that we use an intermediate macro to allow x to be expanded + if it's a macro itself. + */ + #ifndef wxCOMPILER_BROKEN_CONCAT_OPER + #define wxT(x) wxCONCAT_HELPER(L, x) + #else + #define wxT(x) wxPREPEND_L(x) + #endif #endif /* ASCII/Unicode */ #endif /* !defined(wxT) */ @@ -250,7 +257,14 @@ builds everywhere (see wxStringCharType definition above). */ #if wxUSE_UNICODE_WCHAR - #define wxS(x) wxCONCAT_HELPER(L, x) + /* + As above with wxT(), wxS() argument is expanded if it's a macro. + */ + #ifndef wxCOMPILER_BROKEN_CONCAT_OPER + #define wxS(x) wxCONCAT_HELPER(L, x) + #else + #define wxS(x) wxPREPEND_L(x) + #endif #else /* wxUSE_UNICODE_UTF8 || ANSI */ #define wxS(x) x #endif diff --git a/include/wx/cpp.h b/include/wx/cpp.h index e1267b0325..eb012f5308 100644 --- a/include/wx/cpp.h +++ b/include/wx/cpp.h @@ -28,6 +28,16 @@ /* a Unicode-friendly version of wxSTRINGIZE_T */ #define wxSTRINGIZE_T(x) wxAPPLY_T(wxSTRINGIZE(x)) +/* + Special workarounds for compilers with broken "##" operator. For all the + other ones we can just use it directly. + */ +#ifdef wxCOMPILER_BROKEN_CONCAT_OPER + #define wxPREPEND_L(x) L ## x + #define wxAPPEND_i64(x) x ## i64 + #define wxAPPEND_ui64(x) x ## ui64 +#endif /* wxCOMPILER_BROKEN_CONCAT_OPER */ + /* Helper macros for wxMAKE_UNIQUE_NAME: normally this works by appending the current line number to the given identifier to reduce the probability of the diff --git a/include/wx/defs.h b/include/wx/defs.h index 5dc4696a53..f6ca2542d2 100644 --- a/include/wx/defs.h +++ b/include/wx/defs.h @@ -1056,9 +1056,19 @@ typedef wxUint32 wxDword; #define wxULongLong_t unsigned wxLongLong_t #endif - /* these macros allow to define 64 bit constants in a portable way */ - #define wxLL(x) wxCONCAT(x, wxLongLongSuffix) - #define wxULL(x) wxCONCAT(x, wxCONCAT(u, wxLongLongSuffix)) + /* + wxLL() and wxULL() macros allow to define 64 bit constants in a + portable way. + */ + #ifndef wxCOMPILER_BROKEN_CONCAT_OPER + #define wxLL(x) wxCONCAT(x, wxLongLongSuffix) + #define wxULL(x) wxCONCAT(x, wxCONCAT(u, wxLongLongSuffix)) + #else + // Currently only Borland compiler has broken concatenation operator + // and this compiler is known to use [u]i64 suffix. + #define wxLL(x) wxAPPEND_i64(x) + #define wxULL(x) wxAPPEND_ui64(x) + #endif typedef wxLongLong_t wxInt64; typedef wxULongLong_t wxUint64; diff --git a/include/wx/font.h b/include/wx/font.h index 6d7b46a31a..7ebc53d325 100644 --- a/include/wx/font.h +++ b/include/wx/font.h @@ -378,6 +378,11 @@ extern WXDLLIMPEXP_DATA_CORE(wxFontList*) wxTheFontList; // compilers as it compares elements of different enums #if FUTURE_WXWIN_COMPATIBILITY_3_0 +// Unfortunately some compilers have ambiguity issues when enum comparisons are +// overloaded so we have to disable the overloads in this case, see +// wxCOMPILER_NO_OVERLOAD_ON_ENUM definition in wx/platform.h for more details. +#ifndef wxCOMPILER_NO_OVERLOAD_ON_ENUM + inline bool operator==(wxFontFamily s, wxDeprecatedGUIConstants t) { return static_cast(s) == static_cast(t); } inline bool operator!=(wxFontFamily s, wxDeprecatedGUIConstants t) @@ -391,6 +396,8 @@ inline bool operator==(wxFontWeight s, wxDeprecatedGUIConstants t) inline bool operator!=(wxFontWeight s, wxDeprecatedGUIConstants t) { return !(s == t); } +#endif // // wxCOMPILER_NO_OVERLOAD_ON_ENUM + #endif // FUTURE_WXWIN_COMPATIBILITY_3_0 #endif diff --git a/include/wx/meta/implicitconversion.h b/include/wx/meta/implicitconversion.h index 16ff312e4c..b93a919aac 100644 --- a/include/wx/meta/implicitconversion.h +++ b/include/wx/meta/implicitconversion.h @@ -30,18 +30,28 @@ namespace wxPrivate { +// Helper macro to define a constant inside a template class: it's needed +// because MSVC6 doesn't support initializing static integer members but the +// usual workaround of using enums instead doesn't work for Borland (at least +// in template classes). +#ifdef __VISUALC6__ + #define wxDEFINE_CLASS_INT_CONST(name, value) enum { name = value } +#else + #define wxDEFINE_CLASS_INT_CONST(name, value) static const int name = value +#endif + template struct TypeHierarchy { // consider unknown types (e.g. objects, pointers) to be of highest // level, always convert to them if they occur - enum { level = 9999 }; + wxDEFINE_CLASS_INT_CONST( level, 9999 ); }; #define WX_TYPE_HIERARCHY_LEVEL(level_num, type) \ template<> struct TypeHierarchy \ { \ - enum { level = level_num }; \ + wxDEFINE_CLASS_INT_CONST( level, level_num ); \ } WX_TYPE_HIERARCHY_LEVEL( 1, char); @@ -84,7 +94,7 @@ struct wxImplicitConversionType typedef typename wxIf < // if T2 is "higher" type, convert to it - (int)wxPrivate::TypeHierarchy::level < (int)wxPrivate::TypeHierarchy::level, + (int)(wxPrivate::TypeHierarchy::level) < (int)(wxPrivate::TypeHierarchy::level), T2, // otherwise use T1 T1 diff --git a/include/wx/pen.h b/include/wx/pen.h index 101b8be2de..f6e745bd81 100644 --- a/include/wx/pen.h +++ b/include/wx/pen.h @@ -148,6 +148,11 @@ extern WXDLLIMPEXP_DATA_CORE(wxPenList*) wxThePenList; // compilers as it compares elements of different enums #if FUTURE_WXWIN_COMPATIBILITY_3_0 +// Unfortunately some compilers have ambiguity issues when enum comparisons are +// overloaded so we have to disable the overloads in this case, see +// wxCOMPILER_NO_OVERLOAD_ON_ENUM definition in wx/platform.h for more details. +#ifndef wxCOMPILER_NO_OVERLOAD_ON_ENUM + inline bool operator==(wxPenStyle s, wxDeprecatedGUIConstants t) { return static_cast(s) == static_cast(t); @@ -158,6 +163,8 @@ inline bool operator!=(wxPenStyle s, wxDeprecatedGUIConstants t) return !(s == t); } +#endif // wxCOMPILER_NO_OVERLOAD_ON_ENUM + #endif // FUTURE_WXWIN_COMPATIBILITY_3_0 #endif // _WX_PEN_H_BASE_ diff --git a/include/wx/platform.h b/include/wx/platform.h index 713925585f..21c605a99f 100644 --- a/include/wx/platform.h +++ b/include/wx/platform.h @@ -331,16 +331,38 @@ test for old versions of Borland C, normally need at least 5.82, Turbo explorer, available for free at http://www.turboexplorer.com/downloads */ -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x550) -# error "wxWidgets requires a newer version of Borland, we recommend upgrading to 5.82 (Turbo Explorer). You may at your own risk remove this line and try building but be prepared to get build errors." -#endif /* __BORLANDC__ */ -#if defined(__BORLANDC__) && (__BORLANDC__ < 0x582) && (__BORLANDC__ > 0x559) -# ifndef _USE_OLD_RW_STL -# error "wxWidgets is incompatible with default Borland C++ 5.6 STL library, please add -D_USE_OLD_RW_STL to your bcc32.cfg to use RogueWave STL implementation." -# endif -#endif /* __BORLANDC__ */ +/* + Older versions of Borland C have some compiler bugs that need + workarounds. Mostly pertains to the free command line compiler 5.5.1. +*/ +#if defined(__BORLANDC__) && (__BORLANDC__ <= 0x551) + /* + The Borland free compiler is unable to handle overloaded enum + comparisons under certain conditions e.g. when any class has a + conversion ctor for an integral type and there's an overload to + compare between an integral type and that class type. + */ +# define wxCOMPILER_NO_OVERLOAD_ON_ENUM + + /* + This is needed to overcome bugs in 5.5.1 STL, linking errors will + result if it is not defined. + */ +# define _RWSTD_COMPILE_INSTANTIATE + + /* + Preprocessor in older Borland compilers have major problems + concatenating with ##. Specifically, if the string operands being + concatenated have special meaning (e.g L"str", 123i64 etc) + then ## will not concatenate the operands correctly. + + As a workaround, define wxPREPEND* and wxAPPEND* without using + wxCONCAT_HELPER. + */ +# define wxCOMPILER_BROKEN_CONCAT_OPER +#endif /* __BORLANDC__ */ /* Define Watcom-specific macros. diff --git a/include/wx/propgrid/propgridiface.h b/include/wx/propgrid/propgridiface.h index 027a720c19..5be24550c7 100644 --- a/include/wx/propgrid/propgridiface.h +++ b/include/wx/propgrid/propgridiface.h @@ -1385,7 +1385,8 @@ private: { if ( !m_pState ) return NULL; - return static_cast(m_pState->GetGrid()); + + return m_pState->GetGrid(); } friend class wxPropertyGrid; diff --git a/include/wx/rawbmp.h b/include/wx/rawbmp.h index 0f25a78252..2731869eea 100644 --- a/include/wx/rawbmp.h +++ b/include/wx/rawbmp.h @@ -313,9 +313,6 @@ struct wxPixelDataOut // the pixel format we use typedef wxImagePixelFormat PixelFormat; - // the type of the pixel components - typedef typename PixelFormat::ChannelType ChannelType; - // the pixel data we're working with typedef wxPixelDataOut::wxPixelDataIn PixelData; @@ -411,10 +408,10 @@ struct wxPixelDataOut // ----------- // access to individual colour components - ChannelType& Red() { return m_pRGB[PixelFormat::RED]; } - ChannelType& Green() { return m_pRGB[PixelFormat::GREEN]; } - ChannelType& Blue() { return m_pRGB[PixelFormat::BLUE]; } - ChannelType& Alpha() { return *m_pAlpha; } + PixelFormat::ChannelType& Red() { return m_pRGB[PixelFormat::RED]; } + PixelFormat::ChannelType& Green() { return m_pRGB[PixelFormat::GREEN]; } + PixelFormat::ChannelType& Blue() { return m_pRGB[PixelFormat::BLUE]; } + PixelFormat::ChannelType& Alpha() { return *m_pAlpha; } // address the pixel contents directly (always RGB, without alpha) // diff --git a/include/wx/vector.h b/include/wx/vector.h index 982cd08626..1d785e949d 100644 --- a/include/wx/vector.h +++ b/include/wx/vector.h @@ -118,7 +118,10 @@ private: // Note that we use typedef instead of privately deriving from this (which // would allowed us to omit "Ops::" prefixes below) to keep VC6 happy, // it can't compile code that derives from wxIf<...>::value. - typedef typename wxIf< wxIsMovable::value, + // + // Note that bcc needs the extra parentheses for non-type template + // arguments to compile this expression. + typedef typename wxIf< (wxIsMovable::value), wxPrivate::wxVectorMemOpsMovable, wxPrivate::wxVectorMemOpsGeneric >::value Ops; @@ -452,7 +455,7 @@ namespace wxPrivate // This is a helper for the wxVectorSort function, and should not be used // directly in user's code. template -struct wxVectorSort +struct wxVectorComparator { static int wxCMPFUNC_CONV Compare(const void* pitem1, const void* pitem2, const void* ) @@ -477,7 +480,7 @@ template void wxVectorSort(wxVector& v) { wxQsort(v.begin(), v.size(), sizeof(T), - wxPrivate::wxVectorSort::Compare, NULL); + wxPrivate::wxVectorComparator::Compare, NULL); } diff --git a/src/common/translation.cpp b/src/common/translation.cpp index 90f02759fc..c00339d7a5 100644 --- a/src/common/translation.cpp +++ b/src/common/translation.cpp @@ -1500,8 +1500,8 @@ const wxString& wxTranslations::GetString(const wxString& origString, TRACE_I18N, "string \"%s\"%s not found in %slocale '%s'.", origString, - n != UINT_MAX ? wxString::Format("[%ld]", (long)n) : wxString(), - !domain.empty() ? wxString::Format("domain '%s' ", domain) : wxString(), + (n != UINT_MAX ? wxString::Format("[%ld]", (long)n) : wxString()), + (!domain.empty() ? wxString::Format("domain '%s' ", domain) : wxString()), m_lang ); diff --git a/src/common/xlocale.cpp b/src/common/xlocale.cpp index 24dca049ca..b1c08bade9 100644 --- a/src/common/xlocale.cpp +++ b/src/common/xlocale.cpp @@ -77,7 +77,9 @@ wxXLocale& wxXLocale::GetCLocale() { if ( !gs_cLocale ) { - gs_cLocale = new wxXLocale(static_cast(NULL)); + // NOTE: bcc551 has trouble doing static_cast with incomplete + // type definition. reinterpret_cast used as workaround + gs_cLocale = new wxXLocale( reinterpret_cast(NULL) ); } return *gs_cLocale;