From 8dfd799fd521eaf95d784076c069657b1b47efcb Mon Sep 17 00:00:00 2001 From: orbitcowboy Date: Tue, 29 May 2018 09:54:19 +0200 Subject: [PATCH] Use const for constant local variables in wxWidgets headers This avoids warnings from MSVS 2017 static analyzer when C++ core rule set is activated. Closes https://github.com/wxWidgets/wxWidgets/pull/819 --- include/wx/arrstr.h | 10 +++++----- include/wx/clntdata.h | 2 +- include/wx/event.h | 2 +- include/wx/file.h | 2 +- include/wx/log.h | 6 +++--- include/wx/longlong.h | 2 +- include/wx/msw/ole/oleutils.h | 2 +- include/wx/msw/private/fswatcher.h | 4 ++-- include/wx/string.h | 8 ++++---- 9 files changed, 19 insertions(+), 19 deletions(-) diff --git a/include/wx/arrstr.h b/include/wx/arrstr.h index 23a73fefb8..d716bc0e6b 100644 --- a/include/wx/arrstr.h +++ b/include/wx/arrstr.h @@ -280,9 +280,9 @@ public: pointer operator->() const { return m_ptr; } itor& operator++() { --m_ptr; return *this; } const itor operator++(int) - { reverse_iterator tmp = *this; --m_ptr; return tmp; } + { const reverse_iterator tmp = *this; --m_ptr; return tmp; } itor& operator--() { ++m_ptr; return *this; } - const itor operator--(int) { itor tmp = *this; ++m_ptr; return tmp; } + const itor operator--(int) { const itor tmp = *this; ++m_ptr; return tmp; } bool operator ==(const itor& it) const { return m_ptr == it.m_ptr; } bool operator !=(const itor& it) const { return m_ptr != it.m_ptr; } }; @@ -307,9 +307,9 @@ public: pointer operator->() const { return m_ptr; } itor& operator++() { --m_ptr; return *this; } const itor operator++(int) - { itor tmp = *this; --m_ptr; return tmp; } + { const itor tmp = *this; --m_ptr; return tmp; } itor& operator--() { ++m_ptr; return *this; } - const itor operator--(int) { itor tmp = *this; ++m_ptr; return tmp; } + const itor operator--(int) { const itor tmp = *this; ++m_ptr; return tmp; } bool operator ==(const itor& it) const { return m_ptr == it.m_ptr; } bool operator !=(const itor& it) const { return m_ptr != it.m_ptr; } }; @@ -421,7 +421,7 @@ public: wxString* GetStrings() { if( m_strings ) return m_strings; - size_t count = m_array.GetCount(); + const size_t count = m_array.GetCount(); m_strings = new wxString[count]; for( size_t i = 0; i < count; ++i ) m_strings[i] = m_array[i]; diff --git a/include/wx/clntdata.h b/include/wx/clntdata.h index a41ccc0ea9..0619ff3b6a 100644 --- a/include/wx/clntdata.h +++ b/include/wx/clntdata.h @@ -47,7 +47,7 @@ public: if (it == m_methods.end()) return false; wxShadowObjectMethod method = it->second; - int ret = (*method)(window, param); + const int ret = (*method)(window, param); if (returnValue) *returnValue = ret; return true; diff --git a/include/wx/event.h b/include/wx/event.h index 21fa3924c7..d2b7a5d932 100644 --- a/include/wx/event.h +++ b/include/wx/event.h @@ -972,7 +972,7 @@ public: // propagation level value int StopPropagation() { - int propagationLevel = m_propagationLevel; + const int propagationLevel = m_propagationLevel; m_propagationLevel = wxEVENT_PROPAGATE_NONE; return propagationLevel; } diff --git a/include/wx/file.h b/include/wx/file.h index 00ac471abf..3ca1d4dde4 100644 --- a/include/wx/file.h +++ b/include/wx/file.h @@ -65,7 +65,7 @@ public: // assign an existing file descriptor and get it back from wxFile object void Attach(int lfd) { Close(); m_fd = lfd; m_lasterror = 0; } - int Detach() { int fdOld = m_fd; m_fd = fd_invalid; return fdOld; } + int Detach() { const int fdOld = m_fd; m_fd = fd_invalid; return fdOld; } int fd() const { return m_fd; } // read/write (unbuffered) diff --git a/include/wx/log.h b/include/wx/log.h index 3d7d273cbe..c3d4343ce7 100644 --- a/include/wx/log.h +++ b/include/wx/log.h @@ -244,7 +244,7 @@ public: if ( !m_data ) return false; - wxStringToNumHashMap::const_iterator it = m_data->numValues.find(key); + const wxStringToNumHashMap::const_iterator it = m_data->numValues.find(key); if ( it == m_data->numValues.end() ) return false; @@ -258,7 +258,7 @@ public: if ( !m_data ) return false; - wxStringToStringHashMap::const_iterator it = m_data->strValues.find(key); + const wxStringToStringHashMap::const_iterator it = m_data->strValues.find(key); if ( it == m_data->strValues.end() ) return false; @@ -379,7 +379,7 @@ public: return EnableThreadLogging(enable); #endif // wxUSE_THREADS - bool doLogOld = ms_doLog; + const bool doLogOld = ms_doLog; ms_doLog = enable; return doLogOld; } diff --git a/include/wx/longlong.h b/include/wx/longlong.h index f28a3635c8..3e503c97f6 100644 --- a/include/wx/longlong.h +++ b/include/wx/longlong.h @@ -1060,7 +1060,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; + const wxULongLong ret = wxULongLong(l) - ull; return wxLongLong((wxInt32)ret.GetHi(),ret.GetLo()); } diff --git a/include/wx/msw/ole/oleutils.h b/include/wx/msw/ole/oleutils.h index f334a7a289..ed45e592d0 100644 --- a/include/wx/msw/ole/oleutils.h +++ b/include/wx/msw/ole/oleutils.h @@ -38,7 +38,7 @@ // return true if ok, false otherwise inline bool wxOleInitialize() { - HRESULT + const HRESULT hr = ::OleInitialize(NULL); // RPC_E_CHANGED_MODE indicates that OLE had been already initialized diff --git a/include/wx/msw/private/fswatcher.h b/include/wx/msw/private/fswatcher.h index 7bf034f018..31daa038fc 100644 --- a/include/wx/msw/private/fswatcher.h +++ b/include/wx/msw/private/fswatcher.h @@ -207,7 +207,7 @@ public: wxCHECK_MSG( m_iocp != INVALID_HANDLE_VALUE, false, "IOCP not init" ); // The special values of 0 will make GetStatus() return Status_Exit. - int ret = PostQueuedCompletionStatus(m_iocp, 0, 0, NULL); + const int ret = PostQueuedCompletionStatus(m_iocp, 0, 0, NULL); if (!ret) { wxLogSysError(_("Unable to post completion status")); @@ -244,7 +244,7 @@ public: wxCHECK_MSG( count && watch && overlapped, Status_Error, "Output parameters can't be NULL" ); - int ret = GetQueuedCompletionStatus(m_iocp, count, (ULONG_PTR *)watch, + const int ret = GetQueuedCompletionStatus(m_iocp, count, (ULONG_PTR *)watch, overlapped, INFINITE); if ( ret != 0 ) { diff --git a/include/wx/string.h b/include/wx/string.h index c05eeac92e..75b5a587d4 100644 --- a/include/wx/string.h +++ b/include/wx/string.h @@ -994,7 +994,7 @@ public: // This is logically equivalent to strlen(str.mb_str()) but avoids // actually converting the string to multibyte and just computes the // length that it would have after conversion. - size_t ofs = wxConvLibc.FromWChar(NULL, 0, str.wc_str(), str.length()); + const size_t ofs = wxConvLibc.FromWChar(NULL, 0, str.wc_str(), str.length()); return ofs == wxCONV_FAILED ? 0 : static_cast(ofs); } @@ -2161,17 +2161,17 @@ public: // searching (return starting index, or -1 if not found) int Find(const wxString& sub) const // like strstr { - size_type idx = find(sub); + const size_type idx = find(sub); return (idx == npos) ? wxNOT_FOUND : (int)idx; } int Find(const char *sub) const // like strstr { - size_type idx = find(sub); + const size_type idx = find(sub); return (idx == npos) ? wxNOT_FOUND : (int)idx; } int Find(const wchar_t *sub) const // like strstr { - size_type idx = find(sub); + const size_type idx = find(sub); return (idx == npos) ? wxNOT_FOUND : (int)idx; }