diff options
author | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2018-07-17 11:55:14 +0200 |
---|---|---|
committer | Kjell Ahlstedt <kjellahlstedt@gmail.com> | 2018-07-17 11:55:14 +0200 |
commit | d3ca7e5e260dcf96fe3da8a04fadcd0e4e944971 (patch) | |
tree | 5f803f3b05ceb012314ab8a9dda0d6e413edcaaf | |
parent | fa85bd1161d5d914095d1a3f9b620da294c9af79 (diff) | |
download | glibmm-d3ca7e5e260dcf96fe3da8a04fadcd0e4e944971.tar.gz |
Revert "Avoid compiler warnings from function pointer conversions"
This reverts commit fa85bd1161d5d914095d1a3f9b620da294c9af79.
This can be done in a better way by keeping the union in a template function.
-rw-r--r-- | gio/giomm/socketsource.cc | 26 | ||||
-rw-r--r-- | glib/glibmm/main.cc | 26 | ||||
-rw-r--r-- | tests/giomm_stream_vfuncs/main.cc | 2 | ||||
-rw-r--r-- | tests/glibmm_vector/main.cc | 13 |
4 files changed, 12 insertions, 55 deletions
diff --git a/gio/giomm/socketsource.cc b/gio/giomm/socketsource.cc index 24248c85..76249134 100644 --- a/gio/giomm/socketsource.cc +++ b/gio/giomm/socketsource.cc @@ -54,19 +54,6 @@ 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 @@ -85,13 +72,8 @@ SignalSocket::connect(const sigc::slot<bool(Glib::IOCondition)>& slot, { GSource* const source = g_socket_create_source(socket->gobj(), (GIOCondition)condition, Glib::unwrap(cancellable)); - - 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); + return Glib::Source::attach_signal_source( + slot, priority, source, context_, (GSourceFunc)&giomm_signalsocket_callback); } SignalSocket @@ -122,7 +104,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)), - giomm_socketsource_cb_as_gsourcefunc()) + (GSourceFunc)&giomm_socketsource_callback) { } @@ -130,7 +112,7 @@ SocketSource::SocketSource(GSocket* socket, Glib::IOCondition condition, const Glib::RefPtr<Cancellable>& cancellable) : IOSource( g_socket_create_source(socket, (GIOCondition)condition, Glib::unwrap(cancellable)), - giomm_socketsource_cb_as_gsourcefunc()) + (GSourceFunc)&giomm_socketsource_callback) { } diff --git a/glib/glibmm/main.cc b/glib/glibmm/main.cc index eec2b1cc..7edb8f41 100644 --- a/glib/glibmm/main.cc +++ b/glib/glibmm/main.cc @@ -242,19 +242,6 @@ glibmm_iosource_callback(GIOChannel*, GIOCondition condition, void* data) return 0; } -GSourceFunc glibmm_iosource_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(&glibmm_iosource_callback) pios; - } u; - u.pios = &glibmm_iosource_callback; - return u.ps; -} - /* Only used by SignalChildWatch::connect(). * These don't use Glib::Source, to avoid the unnecessary overhead * of a completely unused wrapper object. @@ -520,12 +507,9 @@ SignalChildWatch::connect(const sigc::slot<void(GPid, int)>& slot, GPid pid, int if (priority != G_PRIORITY_DEFAULT) g_source_set_priority(source, priority); - union { - GSourceFunc ps; - decltype(&glibmm_child_watch_callback) pcw; - } u; - u.pcw = &glibmm_child_watch_callback; - g_source_set_callback(source, u.ps, conn_node, &glibmm_source_destroy_notify_callback); + g_source_set_callback(source, (GSourceFunc)&glibmm_child_watch_callback, + conn_node, + &glibmm_source_destroy_notify_callback); conn_node->install(source); g_source_attach(source, context_); @@ -1247,13 +1231,13 @@ IOSource::IOSource(PollFD::fd_t fd, IOCondition condition) : poll_fd_(fd, condit IOSource::IOSource(const Glib::RefPtr<IOChannel>& channel, IOCondition condition) : Source(g_io_create_watch(channel->gobj(), (GIOCondition)condition), - glibmm_iosource_cb_as_gsourcefunc()) + (GSourceFunc)&glibmm_iosource_callback) { } IOSource::IOSource(GIOChannel* channel, IOCondition condition) : Source(g_io_create_watch(channel, (GIOCondition)condition), - glibmm_iosource_cb_as_gsourcefunc()) + (GSourceFunc)&glibmm_iosource_callback) { } diff --git a/tests/giomm_stream_vfuncs/main.cc b/tests/giomm_stream_vfuncs/main.cc index ad42e989..df1cde20 100644 --- a/tests/giomm_stream_vfuncs/main.cc +++ b/tests/giomm_stream_vfuncs/main.cc @@ -160,7 +160,7 @@ int main(int, char**) return EXIT_FAILURE; } } - catch (const Gio::Error& e) + catch (Gio::Error e) { std::cout << "Gio error: " << e.what() << std::endl; return EXIT_FAILURE; diff --git a/tests/glibmm_vector/main.cc b/tests/glibmm_vector/main.cc index 0f039356..31138cf0 100644 --- a/tests/glibmm_vector/main.cc +++ b/tests/glibmm_vector/main.cc @@ -196,23 +196,14 @@ public: ~Cache() { - // Conversion between different types of function pointers with - // reinterpret_cast can make gcc8 print a warning. - // https://github.com/libsigcplusplus/libsigcplusplus/issues/1 - union { - GFunc pf; - decltype(&g_object_unref) pou; - } u; - u.pou = &g_object_unref; - if (glist_) { - g_list_foreach(glist_, u.pf, nullptr); + g_list_foreach(glist_, reinterpret_cast<GFunc>(g_object_unref), nullptr); g_list_free(glist_); } if (gslist_) { - g_slist_foreach(gslist_, u.pf, nullptr); + g_slist_foreach(gslist_, reinterpret_cast<GFunc>(g_object_unref), nullptr); g_slist_free(gslist_); } if (garray_) |