summaryrefslogtreecommitdiff
path: root/gio
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2018-07-13 18:40:25 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2018-07-13 18:40:25 +0200
commit5d953603f30f0452cb9da35e3083a3fc145c3f57 (patch)
tree311ccd2264d138b275037866303b41befbd41f2b /gio
parentfd8536f95018551150e5e1026545f2f7c036d119 (diff)
downloadglibmm-5d953603f30f0452cb9da35e3083a3fc145c3f57.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')
-rw-r--r--gio/giomm/socketsource.cc24
1 files changed, 21 insertions, 3 deletions
diff --git a/gio/giomm/socketsource.cc b/gio/giomm/socketsource.cc
index af1e9740..8bad8f5b 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
@@ -96,7 +114,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())
{
}