summaryrefslogtreecommitdiff
path: root/gio/giomm/socketsource.cc
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2018-07-13 18:59:01 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2018-07-13 18:59:01 +0200
commitfa85bd1161d5d914095d1a3f9b620da294c9af79 (patch)
treeb7968ff9f236ef05129b2d24179949dd6af02961 /gio/giomm/socketsource.cc
parente30044809d3de348fd44f66940a3840accc49a83 (diff)
downloadglibmm-fa85bd1161d5d914095d1a3f9b620da294c9af79.tar.gz
Avoid compiler warnings from function pointer conversions
gcc8 -Wextra prints a warning when reinterpret_cast is used for conversion between different types of function pointers. Avoid that by instead using a union with members of the two types of function pointers. See https://github.com/libsigcplusplus/libsigcplusplus/issues/1
Diffstat (limited to 'gio/giomm/socketsource.cc')
-rw-r--r--gio/giomm/socketsource.cc26
1 files changed, 22 insertions, 4 deletions
diff --git a/gio/giomm/socketsource.cc b/gio/giomm/socketsource.cc
index 76249134..24248c85 100644
--- a/gio/giomm/socketsource.cc
+++ b/gio/giomm/socketsource.cc
@@ -54,6 +54,19 @@ giomm_socketsource_callback(GSocket*, GIOCondition condition, void* user_data)
return giomm_generic_socket_callback(slot, condition);
}
+GSourceFunc giomm_socketsource_cb_as_gsourcefunc()
+{
+ // Conversion between different types of function pointers with
+ // reinterpret_cast can make gcc8 print a warning.
+ // https://github.com/libsigcplusplus/libsigcplusplus/issues/1
+ union {
+ GSourceFunc ps;
+ decltype(&giomm_socketsource_callback) pss;
+ } u;
+ u.pss = &giomm_socketsource_callback;
+ return u.ps;
+}
+
} // anonymous namespace
namespace Gio
@@ -72,8 +85,13 @@ SignalSocket::connect(const sigc::slot<bool(Glib::IOCondition)>& slot,
{
GSource* const source =
g_socket_create_source(socket->gobj(), (GIOCondition)condition, Glib::unwrap(cancellable));
- return Glib::Source::attach_signal_source(
- slot, priority, source, context_, (GSourceFunc)&giomm_signalsocket_callback);
+
+ union {
+ GSourceFunc ps;
+ decltype(&giomm_signalsocket_callback) pss;
+ } u;
+ u.pss = &giomm_signalsocket_callback;
+ return Glib::Source::attach_signal_source(slot, priority, source, context_, u.ps);
}
SignalSocket
@@ -104,7 +122,7 @@ SocketSource::SocketSource(const Glib::RefPtr<Socket>& socket, Glib::IOCondition
const Glib::RefPtr<Cancellable>& cancellable)
: IOSource(
g_socket_create_source(socket->gobj(), (GIOCondition)condition, Glib::unwrap(cancellable)),
- (GSourceFunc)&giomm_socketsource_callback)
+ giomm_socketsource_cb_as_gsourcefunc())
{
}
@@ -112,7 +130,7 @@ SocketSource::SocketSource(GSocket* socket, Glib::IOCondition condition,
const Glib::RefPtr<Cancellable>& cancellable)
: IOSource(
g_socket_create_source(socket, (GIOCondition)condition, Glib::unwrap(cancellable)),
- (GSourceFunc)&giomm_socketsource_callback)
+ giomm_socketsource_cb_as_gsourcefunc())
{
}