Fix more -Wshorten-64-to-32 occurrences and test for them

Add more static casts to avoid harmless warnings about long and/or
size_t to unsigned int conversions and enable -Wshorten-64-to-32 in the
allheaders test to ensure they don't get introduced again in the future.
This commit is contained in:
Vadim Zeitlin 2023-02-27 13:47:57 +01:00
parent 313a415e2e
commit 7bad8b1060
4 changed files with 13 additions and 7 deletions

View file

@ -87,7 +87,7 @@ public:
virtual bool LoadFile(const wxString& file = wxT("")) override;
virtual bool DisplaySection(int sectionNo) override;
virtual bool DisplaySection(const wxString& section) override { return Display(section); }
virtual bool DisplayBlock(long blockNo) override { return DisplaySection(blockNo); }
virtual bool DisplayBlock(long blockNo) override { return DisplaySection(static_cast<int>(blockNo)); }
virtual bool DisplayTextPopup(const wxString& text, const wxPoint& pos) override;
virtual void SetFrameParameters(const wxString& titleFormat,

View file

@ -88,7 +88,7 @@ public:
// override wxSocketBase::SetTimeout function to avoid that the internal
// m_uiDefaultTimeout goes out-of-sync:
virtual void SetTimeout(long seconds) override
{ SetDefaultTimeout(seconds); }
{ SetDefaultTimeout(static_cast<wxUint32>(seconds)); }
// logging support: each wxProtocol object may have the associated logger

View file

@ -85,8 +85,13 @@ public:
// return the total number of selected items
unsigned GetSelectedCount() const
{
return m_defaultState ? m_count - m_itemsSel.GetCount()
: m_itemsSel.GetCount();
// we can we never have more than UINT_MAX selected items, knowing that
// we store the total number of items in an unsigned m_count, so the
// cast is safe.
return static_cast<unsigned>(
m_defaultState ? m_count - m_itemsSel.GetCount()
: m_itemsSel.GetCount()
);
}
// type of a "cookie" used to preserve the iteration state, this is an

View file

@ -349,13 +349,14 @@
GCC_TURN_OFF(padded)
#endif // gcc >= 4.6
// Do the same for clang too except here we don't bother with the individual
// warnings and just enable the usual ones because clang mostly includes all
// the useful warnings in them anyhow.
// Do the same for clang too except here most of the useful warnings are
// already included in -Wall, so we just need a few more.
#ifdef CLANG_TURN_ON
CLANG_TURN_ON(all)
CLANG_TURN_ON(extra)
CLANG_TURN_ON(pedantic)
CLANG_TURN_ON(shorten-64-to-32)
#endif // clang