Skip to content

Commit efe4089

Browse files
committed
Revert "slot, signal: Avoid compiler warnings from function pointer conversions"
This reverts commit c6262e0. This can be done in a better way by keeping the union in a template function.
1 parent c6262e0 commit efe4089

File tree

2 files changed

+28
-98
lines changed

2 files changed

+28
-98
lines changed

sigc++/functors/macros/slot.h.m4

Lines changed: 5 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -63,17 +63,7 @@ FOR(1, $1,[
6363
inline T_return operator()(LOOP(arg%1_type_ _A_a%1, $1)) const
6464
{
6565
if (!empty() && !blocked())
66-
{
67-
// Conversion between different types of function pointers with
68-
// reinterpret_cast can make gcc8 print a warning.
69-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
70-
union {
71-
internal::hook ph;
72-
call_type pc;
73-
} u;
74-
u.ph = slot_base::rep_->call_;
75-
return (u.pc)(LIST(slot_base::rep_, LOOP(_A_a%1, $1)));
76-
}
66+
return (reinterpret_cast<call_type>(slot_base::rep_->call_))(LIST(slot_base::rep_, LOOP(_A_a%1, $1)));
7767
return T_return();
7868
}
7969
@@ -365,14 +355,7 @@ ifelse($1,0,[
365355
* @return A function pointer formed from call_it().
366356
*/
367357
static hook address()
368-
{
369-
union {
370-
hook ph;
371-
decltype(&call_it) pc;
372-
} u;
373-
u.pc = &call_it;
374-
return u.ph;
375-
}
358+
{ return reinterpret_cast<hook>(&call_it); }
376359
};
377360
378361
])
@@ -500,14 +483,7 @@ struct slot_call
500483
* @return A function pointer formed from call_it().
501484
*/
502485
static hook address()
503-
{
504-
union {
505-
hook ph;
506-
decltype(&call_it) pc;
507-
} u;
508-
u.pc = &call_it;
509-
return u.ph;
510-
}
486+
{ return reinterpret_cast<hook>(&call_it); }
511487
};
512488

513489
/** Abstracts functor execution.
@@ -539,14 +515,7 @@ struct slot_call<T_functor, T_return>
539515
* @return A function pointer formed from call_it().
540516
*/
541517
static hook address()
542-
{
543-
union {
544-
hook ph;
545-
decltype(&call_it) pc;
546-
} u;
547-
u.pc = &call_it;
548-
return u.ph;
549-
}
518+
{ return reinterpret_cast<hook>(&call_it); }
550519
};
551520

552521
} /* namespace internal */
@@ -606,14 +575,7 @@ public:
606575
inline T_return operator()(type_trait_take_t<T_arg>... _A_a) const
607576
{
608577
if (!empty() && !blocked())
609-
{
610-
union {
611-
internal::hook ph;
612-
call_type pc;
613-
} u;
614-
u.ph = slot_base::rep_->call_;
615-
return (u.pc)(slot_base::rep_, _A_a...);
616-
}
578+
return (reinterpret_cast<call_type>(slot_base::rep_->call_))(slot_base::rep_, _A_a...);
617579
return T_return();
618580
}
619581

sigc++/macros/signal.h.m4

Lines changed: 23 additions & 55 deletions
Original file line numberDiff line numberDiff line change
@@ -51,17 +51,7 @@ ifelse($1,0,[dnl
5151
* @return The slot's return value.
5252
*/
5353
T_return operator()(const slot_type& _A_slot) const
54-
{
55-
// Conversion between different types of function pointers with
56-
// reinterpret_cast can make gcc8 print a warning.
57-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
58-
union {
59-
internal::hook ph;
60-
typename slot_type::call_type pc;
61-
} u;
62-
u.ph = _A_slot.rep_->call_;
63-
return (u.pc)(LIST(_A_slot.rep_, LOOP(_A_a%1_, $1)));
64-
}
54+
{ return (reinterpret_cast<typename slot_type::call_type>(_A_slot.rep_->call_))(LIST(_A_slot.rep_, LOOP(_A_a%1_, $1))); }
6555
dnl T_return operator()(const slot_type& _A_slot) const
6656
dnl { return _A_slot(LOOP(_A_a%1_, $1)); }
6757
@@ -160,19 +150,13 @@ FOR(1, $1,[
160150
if (it == slots.end())
161151
return T_return(); // note that 'T_return r_();' doesn't work => define 'r_' after this line and initialize as follows:
162152
163-
union {
164-
internal::hook ph;
165-
call_type pc;
166-
} u;
167-
u.ph = it->rep_->call_;
168-
r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
153+
r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
169154
for (++it; it != slots.end(); ++it)
170-
{
171-
if (it->empty() || it->blocked())
172-
continue;
173-
u.ph = it->rep_->call_;
174-
r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
175-
}
155+
{
156+
if (it->empty() || it->blocked())
157+
continue;
158+
r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
159+
}
176160
}
177161
178162
return r_;
@@ -217,19 +201,13 @@ FOR(1, $1,[
217201
if (it == reverse_iterator_type(slots.begin()))
218202
return T_return(); // note that 'T_return r_();' doesn't work => define 'r_' after this line and initialize as follows:
219203
220-
union {
221-
internal::hook ph;
222-
call_type pc;
223-
} u;
224-
u.ph = it->rep_->call_;
225-
r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
204+
r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
226205
for (++it; it != reverse_iterator_type(slots.begin()); ++it)
227-
{
228-
if (it->empty() || it->blocked())
229-
continue;
230-
u.ph = it->rep_->call_;
231-
r_ = (u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
232-
}
206+
{
207+
if (it->empty() || it->blocked())
208+
continue;
209+
r_ = (reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
210+
}
233211
}
234212
235213
return r_;
@@ -265,17 +243,12 @@ FOR(1, $1,[
265243
signal_exec exec(impl);
266244
temp_slot_list slots(impl->slots_);
267245
268-
union {
269-
internal::hook ph;
270-
call_type pc;
271-
} u;
272246
for (const auto& slot : slots)
273-
{
274-
if (slot.empty() || slot.blocked())
275-
continue;
276-
u.ph = slot.rep_->call_;
277-
(u.pc)(LIST(slot.rep_, LOOP(_A_a%1, $1)));
278-
}
247+
{
248+
if (slot.empty() || slot.blocked())
249+
continue;
250+
(reinterpret_cast<call_type>(slot.rep_->call_))(LIST(slot.rep_, LOOP(_A_a%1, $1)));
251+
}
279252
}
280253
281254
_DEPRECATE_IFDEF_START
@@ -301,17 +274,12 @@ FOR(1, $1,[
301274
typedef std::reverse_iterator<signal_impl::iterator_type, std::random_access_iterator_tag,
302275
slot_base, slot_base&, slot_base*, std::ptrdiff_t> reverse_iterator_type;
303276
#endif
304-
union {
305-
internal::hook ph;
306-
call_type pc;
307-
} u;
308277
for (auto it = reverse_iterator_type(slots.end()); it != reverse_iterator_type(slots.begin()); ++it)
309-
{
310-
if (it->empty() || it->blocked())
311-
continue;
312-
u.ph = it->rep_->call_;
313-
(u.pc)(LIST(it->rep_, LOOP(_A_a%1, $1)));
314-
}
278+
{
279+
if (it->empty() || it->blocked())
280+
continue;
281+
(reinterpret_cast<call_type>(it->rep_->call_))(LIST(it->rep_, LOOP(_A_a%1, $1)));
282+
}
315283
}
316284
_DEPRECATE_IFDEF_END
317285
};

0 commit comments

Comments
 (0)