summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorKjell Ahlstedt <kjellahlstedt@gmail.com>2018-07-16 13:18:31 +0200
committerKjell Ahlstedt <kjellahlstedt@gmail.com>2018-07-16 13:18:31 +0200
commitefe4089f7decfbefb9fb36a1126275fab4c44b78 (patch)
tree817e5c0465d126208451e574a4f47a2474e21ea4
parentc6262e0a477b35cd9a4a00c34f3f0a44dcd07210 (diff)
downloadsigc++-efe4089f7decfbefb9fb36a1126275fab4c44b78.tar.gz
Revert "slot, signal: Avoid compiler warnings from function pointer conversions"
This reverts commit c6262e0a477b35cd9a4a00c34f3f0a44dcd07210. This can be done in a better way by keeping the union in a template function.
-rw-r--r--sigc++/functors/macros/slot.h.m448
-rw-r--r--sigc++/macros/signal.h.m478
2 files changed, 28 insertions, 98 deletions
diff --git a/sigc++/functors/macros/slot.h.m4 b/sigc++/functors/macros/slot.h.m4
index aa65677..60cccbd 100644
--- a/sigc++/functors/macros/slot.h.m4
+++ b/sigc++/functors/macros/slot.h.m4
@@ -63,17 +63,7 @@ FOR(1, $1,[
inline T_return operator()(LOOP(arg%1_type_ _A_a%1, $1)) const
{
if (!empty() && !blocked())
- {
- // Conversion between different types of function pointers with
- // reinterpret_cast can make gcc8 print a warning.
- // https://github.com/libsigcplusplus/libsigcplusplus/issues/1
- union {
- internal::hook ph;
- call_type pc;
- } u;
- u.ph = slot_base::rep_->call_;
- return (u.pc)(LIST(slot_base::rep_, LOOP(_A_a%1, $1)));
- }
+ return (reinterpret_cast<call_type>(slot_base::rep_->call_))(LIST(slot_base::rep_, LOOP(_A_a%1, $1)));
return T_return();
}
@@ -365,14 +355,7 @@ ifelse($1,0,[
* @return A function pointer formed from call_it().
*/
static hook address()
- {
- union {
- hook ph;
- decltype(&call_it) pc;
- } u;
- u.pc = &call_it;
- return u.ph;
- }
+ { return reinterpret_cast<hook>(&call_it); }
};
])
@@ -500,14 +483,7 @@ struct slot_call
* @return A function pointer formed from call_it().
*/
static hook address()
- {
- union {
- hook ph;
- decltype(&call_it) pc;
- } u;
- u.pc = &call_it;
- return u.ph;
- }
+ { return reinterpret_cast<hook>(&call_it); }
};
/** Abstracts functor execution.
@@ -539,14 +515,7 @@ struct slot_call<T_functor, T_return>
* @return A function pointer formed from call_it().
*/
static hook address()
- {
- union {
- hook ph;
- decltype(&call_it) pc;
- } u;
- u.pc = &call_it;
- return u.ph;
- }
+ { return reinterpret_cast<hook>(&call_it); }
};
} /* namespace internal */
@@ -606,14 +575,7 @@ public:
inline T_return operator()(type_trait_take_t<T_arg>... _A_a) const
{
if (!empty() && !blocked())
- {
- union {
- internal::hook ph;
- call_type pc;
- } u;
- u.ph = slot_base::rep_->call_;
- return (u.pc)(slot_base::rep_, _A_a...);
- }
+ return (reinterpret_cast<call_type>(slot_base::rep_->call_))(slot_base::rep_, _A_a...);
return T_return();
}
diff --git a/sigc++/macros/signal.h.m4 b/sigc++/macros/signal.h.m4
index 8f7f7d3..8f7ed2a 100644
--- a/sigc++/macros/signal.h.m4
+++ b/sigc++/macros/signal.h.m4
@@ -51,17 +51,7 @@ ifelse($1,0,[dnl
* @return The slot's return value.
*/
T_return operator()(const slot_type& _A_slot) const
- {
- // Conversion between different types of function pointers with
- // reinterpret_cast can make gcc8 print a warning.
- // https://github.com/libsigcplusplus/libsigcplusplus/issues/1
- union {
- internal::hook ph;
- typename slot_type::call_type pc;
- } u;
- u.ph = _A_slot.rep_->call_;
- return (u.pc)(LIST(_A_slot.rep_, LOOP(_A_a%1_, $1)));
- }
+ { return (reinterpret_cast<typename slot_type::call_type>(_A_slot.rep_->call_))(LIST(_A_slot.rep_, LOOP(_A_a%1_, $1))); }
dnl T_return operator()(const slot_type& _A_slot) const
dnl { return _A_slot(LOOP(_A_a%1_, $1)); }
@@ -160,19 +150,13 @@ FOR(1, $1,[
if (it == slots.end())
return T_return(); // note that 'T_return r_();' doesn't work => define 'r_' after this line and initialize as follows:
- union {
- internal::hook ph;
- call_type pc;
- } u;
- u.ph = it->rep_->call_;
- r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
+ r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
for (++it; it != slots.end(); ++it)
- {
- if (it->empty() || it->blocked())
- continue;
- u.ph = it->rep_->call_;
- r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
- }
+ {
+ if (it->empty() || it->blocked())
+ continue;
+ r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
+ }
}
return r_;
@@ -217,19 +201,13 @@ FOR(1, $1,[
if (it == reverse_iterator_type(slots.begin()))
return T_return(); // note that 'T_return r_();' doesn't work => define 'r_' after this line and initialize as follows:
- union {
- internal::hook ph;
- call_type pc;
- } u;
- u.ph = it->rep_->call_;
- r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
+ r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
for (++it; it != reverse_iterator_type(slots.begin()); ++it)
- {
- if (it->empty() || it->blocked())
- continue;
- u.ph = it->rep_->call_;
- r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
- }
+ {
+ if (it->empty() || it->blocked())
+ continue;
+ r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
+ }
}
return r_;
@@ -265,17 +243,12 @@ FOR(1, $1,[
signal_exec exec(impl);
temp_slot_list slots(impl->slots_);
- union {
- internal::hook ph;
- call_type pc;
- } u;
for (const auto& slot : slots)
- {
- if (slot.empty() || slot.blocked())
- continue;
- u.ph = slot.rep_->call_;
- (u.pc)(LIST(slot.rep_, LOOP(_A_a%1, $1)));
- }
+ {
+ if (slot.empty() || slot.blocked())
+ continue;
+ (reinterpret_cast<call_type>(slot.rep_->call_))(LIST(slot.rep_, LOOP(_A_a%1, $1)));
+ }
}
_DEPRECATE_IFDEF_START
@@ -301,17 +274,12 @@ FOR(1, $1,[
typedef std::reverse_iterator<signal_impl::iterator_type, std::random_access_iterator_tag,
slot_base, slot_base&, slot_base*, std::ptrdiff_t> reverse_iterator_type;
#endif
- union {
- internal::hook ph;
- call_type pc;
- } u;
for (auto it = reverse_iterator_type(slots.end()); it != reverse_iterator_type(slots.begin()); ++it)
- {
- if (it->empty() || it->blocked())
- continue;
- u.ph = it->rep_->call_;
- (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
- }
+ {
+ if (it->empty() || it->blocked())
+ continue;
+ (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
+ }
}
_DEPRECATE_IFDEF_END
};