Merge branch 'gcc-wextra'

Enable -Wextra for the Unix CI builds after fixing all the existing
warnings.

See #23662.
This commit is contained in:
Vadim Zeitlin 2023-07-08 00:36:47 +02:00
commit d1ee86df3c
22 changed files with 72 additions and 48 deletions

View file

@ -93,6 +93,7 @@ jobs:
compiler: g++-4.8 compiler: g++-4.8
container: ubuntu:18.04 container: ubuntu:18.04
configure_flags: --disable-shared configure_flags: --disable-shared
allow_extra_warnings: true
use_xvfb: true use_xvfb: true
- name: Ubuntu 18.04 wxGTK 3 compatible 3.0 - name: Ubuntu 18.04 wxGTK 3 compatible 3.0
runner: ubuntu-latest runner: ubuntu-latest
@ -233,7 +234,10 @@ jobs:
esac esac
if [ -z ${{ matrix.allow_warnings }} ]; then if [ -z ${{ matrix.allow_warnings }} ]; then
error_opts="-Werror $allow_warn_opt" if [ -z ${{ matrix.allow_extra_warnings }} ]; then
error_opts="-Wextra"
fi
error_opts="$error_opts -Werror $allow_warn_opt"
echo "wxMAKEFILE_ERROR_CXXFLAGS=$error_opts" >> $GITHUB_ENV echo "wxMAKEFILE_ERROR_CXXFLAGS=$error_opts" >> $GITHUB_ENV
echo "wxMAKEFILE_CXXFLAGS=$wxMAKEFILE_CXXFLAGS $error_opts" >> $GITHUB_ENV echo "wxMAKEFILE_CXXFLAGS=$wxMAKEFILE_CXXFLAGS $error_opts" >> $GITHUB_ENV
fi fi

View file

@ -27,7 +27,7 @@
#include "wx/thread.h" #include "wx/thread.h"
const wxEventType wxEVT_WORKER = wxNewEventType(); const wxEventType wxEVT_WORKER = wxNewEventType();
#define EVT_WORKER(func) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WORKER, -1, -1, (wxObjectEventFunction) (wxEventFunction) (WorkerEventFunction) & func, (wxObject *) nullptr ), #define EVT_WORKER(func) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WORKER, -1, -1, wxEVENT_HANDLER_CAST(WorkerEventFunction, func), (wxObject *) nullptr ),
const int timeout_val = 1000; const int timeout_val = 1000;

View file

@ -64,7 +64,7 @@ const char *GetSocketErrorMsg(int pSockError)
//event sent by workers to server class //event sent by workers to server class
//after client is served //after client is served
const wxEventType wxEVT_WORKER = wxNewEventType(); const wxEventType wxEVT_WORKER = wxNewEventType();
#define EVT_WORKER(func) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WORKER, -1, -1, (wxObjectEventFunction) (wxEventFunction) (WorkerEventFunction) & func, (wxObject *) nullptr ), #define EVT_WORKER(func) wxDECLARE_EVENT_TABLE_ENTRY( wxEVT_WORKER, -1, -1, wxEVENT_HANDLER_CAST(WorkerEventFunction, func), (wxObject *) nullptr ),
class WorkerEvent : public wxEvent class WorkerEvent : public wxEvent
{ {

View file

@ -170,7 +170,9 @@ public:
); );
#endif // GTK+ 3.6/earlier #endif // GTK+ 3.6/earlier
wxGCC_WARNING_SUPPRESS(ignored-qualifiers)
g_object_ref_sink(widget); g_object_ref_sink(widget);
wxGCC_WARNING_RESTORE(ignored-qualifiers)
(void)Create(parent, wxID_ANY, widget); (void)Create(parent, wxID_ANY, widget);
} }

View file

@ -15,6 +15,8 @@
#include "wx/palette.h" #include "wx/palette.h"
#include <vector>
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
// wxPalette // wxPalette
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -24,34 +26,20 @@ struct wxPaletteEntry
unsigned char red, green, blue; unsigned char red, green, blue;
}; };
class wxPaletteRefData : public wxGDIRefData struct wxPaletteRefData : public wxGDIRefData
{ {
public: wxPaletteRefData() = default;
wxPaletteRefData(); wxPaletteRefData(const wxPaletteRefData& other);
wxPaletteRefData(const wxPaletteRefData& palette);
virtual ~wxPaletteRefData();
int m_count; std::vector<wxPaletteEntry> m_entries;
wxPaletteEntry *m_entries;
}; };
wxPaletteRefData::wxPaletteRefData() // We need to define the copy ctor explicitly because the base class copy
{ // ctor is deleted.
m_count = 0;
m_entries = nullptr;
}
wxPaletteRefData::wxPaletteRefData(const wxPaletteRefData& palette) wxPaletteRefData::wxPaletteRefData(const wxPaletteRefData& palette)
: wxGDIRefData()
{ {
m_count = palette.m_count; m_entries = palette.m_entries;
m_entries = new wxPaletteEntry[m_count];
for ( int i = 0; i < m_count; i++ )
m_entries[i] = palette.m_entries[i];
}
wxPaletteRefData::~wxPaletteRefData()
{
delete[] m_entries;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
@ -77,7 +65,7 @@ wxPalette::~wxPalette()
int wxPalette::GetColoursCount() const int wxPalette::GetColoursCount() const
{ {
if (m_refData) if (m_refData)
return M_PALETTEDATA->m_count; return M_PALETTEDATA->m_entries.size();
return 0; return 0;
} }
@ -90,15 +78,16 @@ bool wxPalette::Create(int n,
UnRef(); UnRef();
m_refData = new wxPaletteRefData(); m_refData = new wxPaletteRefData();
M_PALETTEDATA->m_count = n; M_PALETTEDATA->m_entries.resize(n);
M_PALETTEDATA->m_entries = new wxPaletteEntry[n];
wxPaletteEntry *e = M_PALETTEDATA->m_entries; int i = 0;
for (int i = 0; i < n; i++, e++) for ( wxPaletteEntry& e : M_PALETTEDATA->m_entries )
{ {
e->red = red[i]; e.red = red[i];
e->green = green[i]; e.green = green[i];
e->blue = blue[i]; e.blue = blue[i];
++i;
} }
return true; return true;
@ -113,15 +102,17 @@ int wxPalette::GetPixel( unsigned char red,
int closest = 0; int closest = 0;
double d,distance = 1000.0; // max. dist is 256 double d,distance = 1000.0; // max. dist is 256
wxPaletteEntry *e = M_PALETTEDATA->m_entries; int i = 0;
for (int i = 0; i < M_PALETTEDATA->m_count; i++, e++) for ( const wxPaletteEntry& e : M_PALETTEDATA->m_entries )
{ {
if ((d = 0.299 * abs(red - e->red) + if ((d = 0.299 * abs(red - e.red) +
0.587 * abs(green - e->green) + 0.587 * abs(green - e.green) +
0.114 * abs(blue - e->blue)) < distance) { 0.114 * abs(blue - e.blue)) < distance) {
distance = d; distance = d;
closest = i; closest = i;
} }
++i;
} }
return closest; return closest;
} }
@ -134,7 +125,7 @@ bool wxPalette::GetRGB(int pixel,
if ( !m_refData ) if ( !m_refData )
return false; return false;
if ( pixel < 0 || pixel >= M_PALETTEDATA->m_count ) if ( pixel < 0 || (unsigned)pixel >= M_PALETTEDATA->m_entries.size() )
return false; return false;
wxPaletteEntry& p = M_PALETTEDATA->m_entries[pixel]; wxPaletteEntry& p = M_PALETTEDATA->m_entries[pixel];

View file

@ -356,12 +356,16 @@ wxgtk_webview_handle_method_call(GDBusConnection*,
} }
} // extern "C" } // extern "C"
wxGCC_WARNING_SUPPRESS(missing-field-initializers)
static const GDBusInterfaceVTable interface_vtable = { static const GDBusInterfaceVTable interface_vtable = {
wxgtk_webview_handle_method_call, wxgtk_webview_handle_method_call,
nullptr, nullptr,
nullptr nullptr
}; };
wxGCC_WARNING_RESTORE(missing-field-initializers)
static static
gboolean gboolean
wxgtk_webview_dbus_peer_is_authorized(GCredentials *peer_credentials) wxgtk_webview_dbus_peer_is_authorized(GCredentials *peer_credentials)

View file

@ -248,7 +248,7 @@ public:
if ( !m_state ) if ( !m_state )
{ {
m_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS); m_ctx = xkb_context_new(XKB_CONTEXT_NO_FLAGS);
struct xkb_rule_names names = {0}; xkb_rule_names names{};
names.layout = "us"; names.layout = "us";
m_keymap = xkb_keymap_new_from_names(m_ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS); m_keymap = xkb_keymap_new_from_names(m_ctx, &names, XKB_KEYMAP_COMPILE_NO_FLAGS);
m_state = xkb_state_new(m_keymap); m_state = xkb_state_new(m_keymap);

View file

@ -68,7 +68,8 @@ class wxBrushRefData: public wxGDIRefData
} }
wxBrushRefData( const wxBrushRefData& data ) wxBrushRefData( const wxBrushRefData& data )
: m_qtBrush(data.m_qtBrush) : wxGDIRefData(),
m_qtBrush(data.m_qtBrush)
{ {
m_style = data.m_style; m_style = data.m_style;
} }

View file

@ -50,7 +50,8 @@ class wxCursorRefData: public wxGDIRefData
{ {
public: public:
wxCursorRefData() {} wxCursorRefData() {}
wxCursorRefData( const wxCursorRefData& data ) : m_qtCursor(data.m_qtCursor) {} wxCursorRefData( const wxCursorRefData& data )
: wxGDIRefData(), m_qtCursor(data.m_qtCursor) {}
wxCursorRefData( QCursor &c ) : m_qtCursor(c) {} wxCursorRefData( QCursor &c ) : m_qtCursor(c) {}
QCursor m_qtCursor; QCursor m_qtCursor;

View file

@ -361,6 +361,7 @@ wxRegionIterator::wxRegionIterator(const wxRegion& region)
} }
wxRegionIterator::wxRegionIterator(const wxRegionIterator& ri) wxRegionIterator::wxRegionIterator(const wxRegionIterator& ri)
: wxObject()
{ {
m_qtRects = new QVector< QRect >( *ri.m_qtRects ); m_qtRects = new QVector< QRect >( *ri.m_qtRects );
m_pos = ri.m_pos; m_pos = ri.m_pos;

@ -1 +1 @@
Subproject commit 7cab74cefa54851e99b8c06bd6e2cd659b4958ae Subproject commit e1fc0520777932a6c2d5d82eca4911ee264e7b8d

@ -1 +1 @@
Subproject commit b662e55b3d8143bdad94e9a373679c0bfa3f834d Subproject commit 0b90f31ced23241054e8088abb50babe9a44ae67

View file

@ -1392,7 +1392,10 @@ wxThreadError wxThread::Run()
void wxThread::SetPriority(unsigned int prio) void wxThread::SetPriority(unsigned int prio)
{ {
wxCHECK_RET( wxPRIORITY_MIN <= prio && prio <= wxPRIORITY_MAX, // Don't compare with wxPRIORITY_MIN as long as it is 0, as the comparison
// would be always true.
static_assert( wxPRIORITY_MIN == 0, "update the check below" );
wxCHECK_RET( /* wxPRIORITY_MIN <= prio && */ prio <= wxPRIORITY_MAX,
wxT("invalid thread priority") ); wxT("invalid thread priority") );
wxCriticalSectionLocker lock(m_critsect); wxCriticalSectionLocker lock(m_critsect);

View file

@ -59,6 +59,7 @@ wxMask::wxMask()
} }
wxMask::wxMask(const wxMask& mask) wxMask::wxMask(const wxMask& mask)
: wxObject()
{ {
m_display = mask.m_display; m_display = mask.m_display;
if ( !mask.m_bitmap ) if ( !mask.m_bitmap )
@ -285,6 +286,7 @@ wxBitmapRefData::wxBitmapRefData()
} }
wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data) wxBitmapRefData::wxBitmapRefData(const wxBitmapRefData& data)
: wxGDIRefData()
{ {
m_pixmap = 0; m_pixmap = 0;
m_bitmap = 0; m_bitmap = 0;

View file

@ -32,6 +32,7 @@ public:
} }
wxBrushRefData( const wxBrushRefData& data ) wxBrushRefData( const wxBrushRefData& data )
: wxGDIRefData()
{ {
m_style = data.m_style; m_style = data.m_style;
m_stipple = data.m_stipple; m_stipple = data.m_stipple;

View file

@ -38,6 +38,7 @@ public:
} }
wxColourRefData(const wxColourRefData& data) wxColourRefData(const wxColourRefData& data)
: wxGDIRefData()
{ {
m_color = data.m_color; m_color = data.m_color;
m_colormap = data.m_colormap; m_colormap = data.m_colormap;

View file

@ -37,6 +37,7 @@ public:
} }
wxPenRefData( const wxPenRefData& data ) wxPenRefData( const wxPenRefData& data )
: wxGDIRefData()
{ {
m_style = data.m_style; m_style = data.m_style;
m_width = data.m_width; m_width = data.m_width;

View file

@ -39,6 +39,7 @@ public:
} }
wxRegionRefData(const wxRegionRefData& refData) wxRegionRefData(const wxRegionRefData& refData)
: wxGDIRefData()
{ {
m_region = XCreateRegion(); m_region = XCreateRegion();
XUnionRegion( refData.m_region, m_region, m_region ); XUnionRegion( refData.m_region, m_region, m_region );

View file

@ -479,8 +479,8 @@ class wxMyVariantData : public wxVariantData
{ {
public: public:
wxMyVariantData(const MyClass& value) wxMyVariantData(const MyClass& value)
: m_value(value)
{ {
m_value = value;
} }
virtual bool Eq(wxVariantData& WXUNUSED(data)) const override virtual bool Eq(wxVariantData& WXUNUSED(data)) const override

View file

@ -165,10 +165,13 @@ TEST_CASE("Event::BuiltinConnect", "[event][connect]")
handler.Connect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnIdle), nullptr, &handler); handler.Connect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnIdle), nullptr, &handler);
handler.Disconnect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnIdle), nullptr, &handler); handler.Disconnect(wxEVT_IDLE, wxIdleEventHandler(MyHandler::OnIdle), nullptr, &handler);
// using casts like this is even uglier than using wxIdleEventHandler but // using casts like this is even uglier than using wxIdleEventHandler and
// it should still continue to work for compatibility // results in warnings with gcc, but it should still continue to work for
// compatibility
wxGCC_WARNING_SUPPRESS_CAST_FUNCTION_TYPE()
handler.Connect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle); handler.Connect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle);
handler.Disconnect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle); handler.Disconnect(wxEVT_IDLE, (wxObjectEventFunction)(wxEventFunction)&MyHandler::OnIdle);
wxGCC_WARNING_RESTORE_CAST_FUNCTION_TYPE()
handler.Bind(wxEVT_IDLE, GlobalOnIdle); handler.Bind(wxEVT_IDLE, GlobalOnIdle);
handler.Unbind(wxEVT_IDLE, GlobalOnIdle); handler.Unbind(wxEVT_IDLE, GlobalOnIdle);

View file

@ -497,6 +497,8 @@ struct MyStruct
class MyHash class MyHash
{ {
public: public:
MyHash() = default;
MyHash(const MyHash&) = default;
unsigned long operator()(const MyStruct& s) const unsigned long operator()(const MyStruct& s) const
{ return m_dummy(s.ptr); } { return m_dummy(s.ptr); }
MyHash& operator=(const MyHash&) { return *this; } MyHash& operator=(const MyHash&) { return *this; }
@ -507,6 +509,8 @@ private:
class MyEqual class MyEqual
{ {
public: public:
MyEqual() = default;
MyEqual(const MyEqual&) = default;
bool operator()(const MyStruct& s1, const MyStruct& s2) const bool operator()(const MyStruct& s1, const MyStruct& s2) const
{ return s1.ptr == s2.ptr; } { return s1.ptr == s2.ptr; }
MyEqual& operator=(const MyEqual&) { return *this; } MyEqual& operator=(const MyEqual&) { return *this; }

View file

@ -252,6 +252,8 @@ wxIMPLEMENT_APP_CONSOLE(XmlResApp);
int XmlResApp::OnRun() int XmlResApp::OnRun()
{ {
wxGCC_WARNING_SUPPRESS(missing-field-initializers)
static const wxCmdLineEntryDesc cmdLineDesc[] = static const wxCmdLineEntryDesc cmdLineDesc[] =
{ {
{ wxCMD_LINE_SWITCH, "h", "help", "show help message", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP }, { wxCMD_LINE_SWITCH, "h", "help", "show help message", wxCMD_LINE_VAL_NONE, wxCMD_LINE_OPTION_HELP },
@ -275,6 +277,8 @@ int XmlResApp::OnRun()
wxCMD_LINE_DESC_END wxCMD_LINE_DESC_END
}; };
wxGCC_WARNING_RESTORE(missing-field-initializers)
wxCmdLineParser parser(cmdLineDesc, argc, argv); wxCmdLineParser parser(cmdLineDesc, argc, argv);
switch (parser.Parse()) switch (parser.Parse())