From 17473a770a4aaed3b0904025f5e3e139441b0909 Mon Sep 17 00:00:00 2001 From: =?utf8?q?V=C3=A1clav=20Slav=C3=ADk?= Date: Wed, 10 Jul 2013 16:41:34 +0000 Subject: [PATCH] Fix lots of warnings reported by Clang. Mostly potentially lossy implicit conversions in headers (long->int). Also dangling else warnings. Struct/class mismatches. git-svn-id: https://svn.wxwidgets.org/svn/wx/wxWidgets/trunk@74473 c3d73ce0-8a6f-49c7-b76d-6d57e0e08775 --- include/wx/dynarray.h | 2 +- include/wx/gdicmn.h | 18 +++++++++--------- include/wx/graphics.h | 2 +- include/wx/hashmap.h | 21 ++++++++------------- include/wx/html/htmlcell.h | 4 ++-- include/wx/html/htmltag.h | 6 +++--- include/wx/html/winpars.h | 2 +- include/wx/list.h | 2 +- include/wx/longlong.h | 2 +- include/wx/osx/carbon/region.h | 2 +- include/wx/sizer.h | 4 ++-- include/wx/statusbr.h | 4 ++-- include/wx/stc/stc.h | 20 ++++++++++---------- include/wx/string.h | 2 +- include/wx/unichar.h | 4 ++-- include/wx/windowid.h | 4 ++-- interface/wx/graphics.h | 2 +- interface/wx/statusbr.h | 2 +- src/common/any.cpp | 4 +++- src/common/filefn.cpp | 2 +- src/common/intl.cpp | 4 +++- src/osx/cocoa/dataview.mm | 4 +++- src/stc/stc.h.in | 20 ++++++++++---------- 23 files changed, 69 insertions(+), 68 deletions(-) diff --git a/include/wx/dynarray.h b/include/wx/dynarray.h index a7ebbfe176..2b78615e7a 100644 --- a/include/wx/dynarray.h +++ b/include/wx/dynarray.h @@ -251,7 +251,7 @@ protected: \ typedef const value_type* const_iterator; \ typedef value_type& reference; \ typedef const value_type& const_reference; \ - typedef int difference_type; \ + typedef ptrdiff_t difference_type; \ typedef size_t size_type; \ \ void assign(const_iterator first, const_iterator last); \ diff --git a/include/wx/gdicmn.h b/include/wx/gdicmn.h index 624c495072..eeb848f1d6 100644 --- a/include/wx/gdicmn.h +++ b/include/wx/gdicmn.h @@ -381,27 +381,27 @@ inline wxSize operator/(const wxSize& s, long i) inline wxSize operator*(const wxSize& s, long i) { - return wxSize(s.x * i, s.y * i); + return wxSize(int(s.x * i), int(s.y * i)); } inline wxSize operator*(long i, const wxSize& s) { - return wxSize(s.x * i, s.y * i); + return wxSize(int(s.x * i), int(s.y * i)); } inline wxSize operator/(const wxSize& s, unsigned long i) { - return wxSize(s.x / i, s.y / i); + return wxSize(int(s.x / i), int(s.y / i)); } inline wxSize operator*(const wxSize& s, unsigned long i) { - return wxSize(s.x * i, s.y * i); + return wxSize(int(s.x * i), int(s.y * i)); } inline wxSize operator*(unsigned long i, const wxSize& s) { - return wxSize(s.x * i, s.y * i); + return wxSize(int(s.x * i), int(s.y * i)); } inline wxSize operator*(const wxSize& s, double i) @@ -655,12 +655,12 @@ inline wxPoint operator/(const wxPoint& s, long i) inline wxPoint operator*(const wxPoint& s, long i) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(int(s.x * i), int(s.y * i)); } inline wxPoint operator*(long i, const wxPoint& s) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(int(s.x * i), int(s.y * i)); } inline wxPoint operator/(const wxPoint& s, unsigned long i) @@ -670,12 +670,12 @@ inline wxPoint operator/(const wxPoint& s, unsigned long i) inline wxPoint operator*(const wxPoint& s, unsigned long i) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(int(s.x * i), int(s.y * i)); } inline wxPoint operator*(unsigned long i, const wxPoint& s) { - return wxPoint(s.x * i, s.y * i); + return wxPoint(int(s.x * i), int(s.y * i)); } inline wxPoint operator*(const wxPoint& s, double i) diff --git a/include/wx/graphics.h b/include/wx/graphics.h index 656a338d3b..6b1a0ee5f1 100644 --- a/include/wx/graphics.h +++ b/include/wx/graphics.h @@ -398,7 +398,7 @@ public: void Add(wxColour col, float pos) { Add(wxGraphicsGradientStop(col, pos)); } // Get the number of stops. - unsigned GetCount() const { return m_stops.size(); } + size_t GetCount() const { return m_stops.size(); } // Return the stop at the given index (which must be valid). wxGraphicsGradientStop Item(unsigned n) const { return m_stops.at(n); } diff --git a/include/wx/hashmap.h b/include/wx/hashmap.h index 9a25f8e183..3fc44993a4 100644 --- a/include/wx/hashmap.h +++ b/include/wx/hashmap.h @@ -483,8 +483,9 @@ inline bool grow_lf70( size_t buckets, size_t items ) #ifndef wxNEEDS_WX_HASH_MAP // integer types -class WXDLLIMPEXP_BASE wxIntegerHash +struct WXDLLIMPEXP_BASE wxIntegerHash { +private: WX_HASH_MAP_NAMESPACE::hash longHash; WX_HASH_MAP_NAMESPACE::hash ulongHash; WX_HASH_MAP_NAMESPACE::hash intHash; @@ -527,9 +528,8 @@ public: #else // wxNEEDS_WX_HASH_MAP // integer types -class WXDLLIMPEXP_BASE wxIntegerHash +struct WXDLLIMPEXP_BASE wxIntegerHash { -public: wxIntegerHash() { } unsigned long operator()( long x ) const { return (unsigned long)x; } unsigned long operator()( unsigned long x ) const { return x; } @@ -547,9 +547,8 @@ public: #endif // !wxNEEDS_WX_HASH_MAP/wxNEEDS_WX_HASH_MAP -class WXDLLIMPEXP_BASE wxIntegerEqual +struct WXDLLIMPEXP_BASE wxIntegerEqual { -public: wxIntegerEqual() { } bool operator()( long a, long b ) const { return a == b; } bool operator()( unsigned long a, unsigned long b ) const { return a == b; } @@ -566,9 +565,8 @@ public: }; // pointers -class WXDLLIMPEXP_BASE wxPointerHash +struct WXDLLIMPEXP_BASE wxPointerHash { -public: wxPointerHash() { } #ifdef wxNEEDS_WX_HASH_MAP @@ -580,9 +578,8 @@ public: wxPointerHash& operator=(const wxPointerHash&) { return *this; } }; -class WXDLLIMPEXP_BASE wxPointerEqual +struct WXDLLIMPEXP_BASE wxPointerEqual { -public: wxPointerEqual() { } bool operator()( const void* a, const void* b ) const { return a == b; } @@ -590,9 +587,8 @@ public: }; // wxString, char*, wchar_t* -class WXDLLIMPEXP_BASE wxStringHash +struct WXDLLIMPEXP_BASE wxStringHash { -public: wxStringHash() {} unsigned long operator()( const wxString& x ) const { return stringHash( x.wx_str() ); } @@ -616,9 +612,8 @@ public: wxStringHash& operator=(const wxStringHash&) { return *this; } }; -class WXDLLIMPEXP_BASE wxStringEqual +struct WXDLLIMPEXP_BASE wxStringEqual { -public: wxStringEqual() {} bool operator()( const wxString& a, const wxString& b ) const { return a == b; } diff --git a/include/wx/html/htmlcell.h b/include/wx/html/htmlcell.h index c0d03c8a26..c42299eb26 100644 --- a/include/wx/html/htmlcell.h +++ b/include/wx/html/htmlcell.h @@ -345,9 +345,9 @@ protected: wxHtmlContainerCell *m_Parent; // dimensions of fragment (m_Descent is used to position text & images) - long m_Width, m_Height, m_Descent; + int m_Width, m_Height, m_Descent; // position where the fragment is drawn: - long m_PosX, m_PosY; + int m_PosX, m_PosY; // superscript/subscript/normal: wxHtmlScriptMode m_ScriptMode; diff --git a/include/wx/html/htmltag.h b/include/wx/html/htmltag.h index 4ff2164beb..cde771ae7d 100644 --- a/include/wx/html/htmltag.h +++ b/include/wx/html/htmltag.h @@ -165,9 +165,9 @@ private: #if WXWIN_COMPATIBILITY_2_8 -inline int wxHtmlTag::GetBeginPos() const { return m_Begin - m_sourceStart; } -inline int wxHtmlTag::GetEndPos1() const { return m_End1 - m_sourceStart; } -inline int wxHtmlTag::GetEndPos2() const { return m_End2 - m_sourceStart; } +inline int wxHtmlTag::GetBeginPos() const { return int(m_Begin - m_sourceStart); } +inline int wxHtmlTag::GetEndPos1() const { return int(m_End1 - m_sourceStart); } +inline int wxHtmlTag::GetEndPos2() const { return int(m_End2 - m_sourceStart); } #endif // WXWIN_COMPATIBILITY_2_8 diff --git a/include/wx/html/winpars.h b/include/wx/html/winpars.h index 3347e4e369..978e19fb54 100644 --- a/include/wx/html/winpars.h +++ b/include/wx/html/winpars.h @@ -204,7 +204,7 @@ private: // actual hypertext link or empty string bool m_UseLink; // true if m_Link is not empty - long m_CharHeight, m_CharWidth; + int m_CharHeight, m_CharWidth; // average height of normal-sized text int m_Align; // actual alignment diff --git a/include/wx/list.h b/include/wx/list.h index ed34130a16..7a96c25152 100644 --- a/include/wx/list.h +++ b/include/wx/list.h @@ -218,7 +218,7 @@ inline const void *wxListCastElementToVoidPtr(const wxString& str) } \ int IndexOf() const \ { \ - return *this ? std::distance( m_list->begin(), m_iter ) \ + return *this ? (int)std::distance( m_list->begin(), m_iter ) \ : wxNOT_FOUND; \ } \ }; \ diff --git a/include/wx/longlong.h b/include/wx/longlong.h index 19c580110e..9af6691913 100644 --- a/include/wx/longlong.h +++ b/include/wx/longlong.h @@ -1067,7 +1067,7 @@ inline wxULongLong operator+(unsigned long l, const wxULongLong& ull) { return u inline wxLongLong operator-(unsigned long l, const wxULongLong& ull) { wxULongLong ret = wxULongLong(l) - ull; - return wxLongLong((long)ret.GetHi(),ret.GetLo()); + return wxLongLong((wxInt32)ret.GetHi(),ret.GetLo()); } #if wxUSE_LONGLONG_NATIVE && wxUSE_STREAMS diff --git a/include/wx/osx/carbon/region.h b/include/wx/osx/carbon/region.h index eec9be0037..a1eb18a64b 100644 --- a/include/wx/osx/carbon/region.h +++ b/include/wx/osx/carbon/region.h @@ -87,7 +87,7 @@ public: long GetWidth() const { return GetW(); } long GetH() const; long GetHeight() const { return GetH(); } - wxRect GetRect() const { return wxRect(GetX(), GetY(), GetWidth(), GetHeight()); } + wxRect GetRect() const { return wxRect((int)GetX(), (int)GetY(), (int)GetWidth(), (int)GetHeight()); } private: void SetRects(long numRects, wxRect *rects); diff --git a/include/wx/sizer.h b/include/wx/sizer.h index 29facff1e2..e11720a4e0 100644 --- a/include/wx/sizer.h +++ b/include/wx/sizer.h @@ -814,7 +814,7 @@ protected: "Can't calculate number of cols if number of rows is not specified" ); - return (m_children.GetCount() + m_rows - 1) / m_rows; + return int(m_children.GetCount() + m_rows - 1) / m_rows; } int CalcRows() const @@ -825,7 +825,7 @@ protected: "Can't calculate number of cols if number of rows is not specified" ); - return (m_children.GetCount() + m_cols - 1) / m_cols; + return int(m_children.GetCount() + m_cols - 1) / m_cols; } private: diff --git a/include/wx/statusbr.h b/include/wx/statusbr.h index 52e134f19e..335cea8302 100644 --- a/include/wx/statusbr.h +++ b/include/wx/statusbr.h @@ -54,7 +54,7 @@ extern WXDLLIMPEXP_DATA_CORE(const char) wxStatusBarNameStr[]; class WXDLLIMPEXP_CORE wxStatusBarPane { public: - wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0) + wxStatusBarPane(int style = wxSB_NORMAL, int width = 0) : m_nStyle(style), m_nWidth(width) { m_bEllipsized = false; } @@ -120,7 +120,7 @@ public: // set the number of fields and call SetStatusWidths(widths) if widths are // given virtual void SetFieldsCount(int number = 1, const int *widths = NULL); - int GetFieldsCount() const { return m_panes.GetCount(); } + int GetFieldsCount() const { return (int)m_panes.GetCount(); } // field text // ---------- diff --git a/include/wx/stc/stc.h b/include/wx/stc/stc.h index c406e6a687..a5c8ed8001 100644 --- a/include/wx/stc/stc.h +++ b/include/wx/stc/stc.h @@ -4557,8 +4557,8 @@ public: } virtual void Replace(long from, long to, const wxString& text) { - SetTargetStart(from); - SetTargetEnd(to); + SetTargetStart((int)from); + SetTargetEnd((int)to); ReplaceTarget(text); } @@ -4579,7 +4579,7 @@ public: virtual void SetInsertionPoint(long pos) { - SetCurrentPos(pos == -1 ? GetLastPosition() : pos); + SetCurrentPos(int(pos == -1 ? GetLastPosition() : pos)); } virtual long GetInsertionPoint() const { return GetCurrentPos(); } virtual long GetLastPosition() const { return GetTextLength(); } @@ -4592,8 +4592,8 @@ public: } else { - SetSelectionStart(from); - SetSelectionEnd(to); + SetSelectionStart((int)from); + SetSelectionEnd((int)to); } } @@ -4619,9 +4619,9 @@ public: long f, t; GetSelection(&f, &t); if ( from ) - *from = f; + *from = (int)f; if ( to ) - *to = t; + *to = (int)t; } #endif @@ -4673,14 +4673,14 @@ public: virtual long XYToPosition(long x, long y) const { - long pos = PositionFromLine(y); + long pos = PositionFromLine((int)y); pos += x; return pos; } virtual bool PositionToXY(long pos, long *x, long *y) const { - long l = LineFromPosition(pos); + int l = LineFromPosition((int)pos); if ( l == -1 ) return false; @@ -4693,7 +4693,7 @@ public: return true; } - virtual void ShowPosition(long pos) { GotoPos(pos); } + virtual void ShowPosition(long pos) { GotoPos((int)pos); } // FIXME-VC6: can't use wxWindow here because of "error C2603: illegal // access declaration: 'wxWindow' is not a direct base of diff --git a/include/wx/string.h b/include/wx/string.h index 53ae8907d8..ad47cd2fbc 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -889,7 +889,7 @@ public: public: \ WX_DEFINE_ITERATOR_CATEGORY(WX_STR_ITERATOR_TAG) \ typedef wxUniChar value_type; \ - typedef int difference_type; \ + typedef ptrdiff_t difference_type; \ typedef reference_type reference; \ typedef pointer_type pointer; \ \ diff --git a/include/wx/unichar.h b/include/wx/unichar.h index be2ce619ed..f2ca9c3df4 100644 --- a/include/wx/unichar.h +++ b/include/wx/unichar.h @@ -36,7 +36,7 @@ public: wxUniChar(unsigned char c) { m_value = From8bit((char)c); } #define wxUNICHAR_DEFINE_CTOR(type) \ - wxUniChar(type c) { m_value = c; } + wxUniChar(type c) { m_value = (value_type)c; } wxDO_FOR_INT_TYPES(wxUNICHAR_DEFINE_CTOR) #undef wxUNICHAR_DEFINE_CTOR @@ -112,7 +112,7 @@ public: wxUniChar& operator=(unsigned char c) { m_value = From8bit((char)c); return *this; } #define wxUNICHAR_DEFINE_OPERATOR_EQUAL(type) \ - wxUniChar& operator=(type c) { m_value = c; return *this; } + wxUniChar& operator=(type c) { m_value = (value_type)c; return *this; } wxDO_FOR_INT_TYPES(wxUNICHAR_DEFINE_OPERATOR_EQUAL) #undef wxUNICHAR_DEFINE_OPERATOR_EQUAL diff --git a/include/wx/windowid.h b/include/wx/windowid.h index e16b4534ab..2360085c7f 100644 --- a/include/wx/windowid.h +++ b/include/wx/windowid.h @@ -43,7 +43,7 @@ public: wxWindowIDRef(long id) { - Init(id); + Init(wxWindowID(id)); } wxWindowIDRef(const wxWindowIDRef& id) @@ -66,7 +66,7 @@ public: wxWindowIDRef& operator=(long id) { - Assign(id); + Assign(wxWindowID(id)); return *this; } diff --git a/interface/wx/graphics.h b/interface/wx/graphics.h index a8ebbabd67..2f052a5f08 100644 --- a/interface/wx/graphics.h +++ b/interface/wx/graphics.h @@ -981,7 +981,7 @@ public: /** Returns the number of stops. */ - unsigned GetCount() const; + size_t GetCount() const; /** Set the start colour to @a col diff --git a/interface/wx/statusbr.h b/interface/wx/statusbr.h index 8070fe0c10..5474d0eb87 100644 --- a/interface/wx/statusbr.h +++ b/interface/wx/statusbr.h @@ -39,7 +39,7 @@ public: /** Constructs the pane with the given @a style and @a width. */ - wxStatusBarPane(int style = wxSB_NORMAL, size_t width = 0); + wxStatusBarPane(int style = wxSB_NORMAL, int width = 0); /** Returns the pane width; it maybe negative, indicating a variable-width field. diff --git a/src/common/any.cpp b/src/common/any.cpp index cefcc2a1d8..228f1770b3 100644 --- a/src/common/any.cpp +++ b/src/common/any.cpp @@ -484,7 +484,9 @@ WX_IMPLEMENT_ANY_VALUE_TYPE(wxAnyValueTypeImpl) class wxAnyNullValue { -private: +protected: + // this field is unused, but can't be private to avoid Clang's + // "Private field 'm_dummy' is not used" warning void* m_dummy; }; diff --git a/src/common/filefn.cpp b/src/common/filefn.cpp index 061ea5f7c3..f723d120db 100644 --- a/src/common/filefn.cpp +++ b/src/common/filefn.cpp @@ -1390,7 +1390,7 @@ wxChar *wxDoGetCwd(wxChar *buf, int sz) buf = new wxChar[sz + 1]; } - bool ok wxDUMMY_INITIALIZE(false); + bool ok = false; // for the compilers which have Unicode version of _getcwd(), call it // directly, for the others call the ANSI version and do the translation diff --git a/src/common/intl.cpp b/src/common/intl.cpp index 16bdbd4563..57919559a4 100644 --- a/src/common/intl.cpp +++ b/src/common/intl.cpp @@ -571,12 +571,14 @@ bool wxLocale::Init(int language, int flags) namespace { +#ifndef __WXOSX__ // Small helper function: get the value of the given environment variable and // return true only if the variable was found and has non-empty value. inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value) { return wxGetEnv(name, value) && !value->empty(); } +#endif } // anonymous namespace @@ -591,7 +593,7 @@ inline bool wxGetNonEmptyEnvVar(const wxString& name, wxString* value) #if defined(__UNIX__) // first get the string identifying the language from the environment wxString langFull; -#ifdef __WXMAC__ +#ifdef __WXOSX__ wxCFRef userLocaleRef(CFLocaleCopyCurrent()); // because the locale identifier (kCFLocaleIdentifier) is formatted a little bit differently, eg diff --git a/src/osx/cocoa/dataview.mm b/src/osx/cocoa/dataview.mm index 465305fbbc..5bae6bb0f2 100644 --- a/src/osx/cocoa/dataview.mm +++ b/src/osx/cocoa/dataview.mm @@ -965,6 +965,7 @@ outlineView:(NSOutlineView*)outlineView delete[] dataFormats; delete itemObject; if (dataStringAvailable) + { if (itemStringAvailable) { if (itemCounter > 0) @@ -973,6 +974,7 @@ outlineView:(NSOutlineView*)outlineView } else dataStringAvailable = false; + } } else { @@ -1701,7 +1703,7 @@ outlineView:(NSOutlineView*)outlineView NSArray* sortDescriptors; NSSortDescriptor* sortDescriptor; - sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[NSString stringWithFormat:@"%d",[outlineView columnWithIdentifier:[tableColumn identifier]]] + sortDescriptor = [[NSSortDescriptor alloc] initWithKey:[NSString stringWithFormat:@"%ld",(long)[outlineView columnWithIdentifier:[tableColumn identifier]]] ascending:YES]; sortDescriptors = [NSArray arrayWithObject:sortDescriptor]; [tableColumn setSortDescriptorPrototype:sortDescriptor]; diff --git a/src/stc/stc.h.in b/src/stc/stc.h.in index b82bea900c..009ca23df6 100644 --- a/src/stc/stc.h.in +++ b/src/stc/stc.h.in @@ -299,8 +299,8 @@ public: } virtual void Replace(long from, long to, const wxString& text) { - SetTargetStart(from); - SetTargetEnd(to); + SetTargetStart((int)from); + SetTargetEnd((int)to); ReplaceTarget(text); } @@ -321,7 +321,7 @@ public: virtual void SetInsertionPoint(long pos) { - SetCurrentPos(pos == -1 ? GetLastPosition() : pos); + SetCurrentPos(int(pos == -1 ? GetLastPosition() : pos)); } virtual long GetInsertionPoint() const { return GetCurrentPos(); } virtual long GetLastPosition() const { return GetTextLength(); } @@ -334,8 +334,8 @@ public: } else { - SetSelectionStart(from); - SetSelectionEnd(to); + SetSelectionStart((int)from); + SetSelectionEnd((int)to); } } @@ -361,9 +361,9 @@ public: long f, t; GetSelection(&f, &t); if ( from ) - *from = f; + *from = (int)f; if ( to ) - *to = t; + *to = (int)t; } #endif @@ -415,14 +415,14 @@ public: virtual long XYToPosition(long x, long y) const { - long pos = PositionFromLine(y); + long pos = PositionFromLine((int)y); pos += x; return pos; } virtual bool PositionToXY(long pos, long *x, long *y) const { - long l = LineFromPosition(pos); + int l = LineFromPosition((int)pos); if ( l == -1 ) return false; @@ -435,7 +435,7 @@ public: return true; } - virtual void ShowPosition(long pos) { GotoPos(pos); } + virtual void ShowPosition(long pos) { GotoPos((int)pos); } // FIXME-VC6: can't use wxWindow here because of "error C2603: illegal // access declaration: 'wxWindow' is not a direct base of -- 2.45.2