Skip to content

Commit 1aabb89

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

File tree

2 files changed

+6
-43
lines changed

2 files changed

+6
-43
lines changed

sigc++/functors/slot.h

Lines changed: 3 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -134,18 +134,7 @@ struct slot_call
134134
/** Forms a function pointer from call_it().
135135
* @return A function pointer formed from call_it().
136136
*/
137-
static hook address()
138-
{
139-
// Conversion between different types of function pointers with
140-
// reinterpret_cast can make gcc8 print a warning.
141-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
142-
union {
143-
hook ph;
144-
decltype(&call_it) pc;
145-
} u;
146-
u.pc = &call_it;
147-
return u.ph;
148-
}
137+
static hook address() { return reinterpret_cast<hook>(&call_it); }
149138
};
150139

151140
} /* namespace internal */
@@ -202,17 +191,8 @@ class slot<T_return(T_arg...)> : public slot_base
202191
*/
203192
inline T_return operator()(type_trait_take_t<T_arg>... a) const
204193
{
205-
if (!empty() && !blocked())
206-
{
207-
// Conversion between different types of function pointers with
208-
// reinterpret_cast can make gcc8 print a warning.
209-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
210-
union {
211-
internal::hook ph;
212-
call_type pc;
213-
} u;
214-
u.ph = slot_base::rep_->call_;
215-
return std::invoke(u.pc, slot_base::rep_, a...);
194+
if (!empty() && !blocked()) {
195+
return std::invoke(reinterpret_cast<call_type>(slot_base::rep_->call_), slot_base::rep_, a...);
216196
}
217197

218198
return T_return();

sigc++/signal.h

Lines changed: 3 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -322,21 +322,12 @@ struct signal_emit<T_return, void, T_arg...>
322322
return T_return();
323323
}
324324

325-
// Conversion between different types of function pointers with
326-
// reinterpret_cast can make gcc8 print a warning.
327-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
328-
union {
329-
internal::hook ph;
330-
call_type pc;
331-
} u;
332-
u.ph = it->rep_->call_;
333-
r_ = (u.pc)(it->rep_, a...);
325+
r_ = (reinterpret_cast<call_type>(it->rep_->call_))(it->rep_, a...);
334326
for (++it; it != slots.end(); ++it)
335327
{
336328
if (it->empty() || it->blocked())
337329
continue;
338-
u.ph = it->rep_->call_;
339-
r_ = (u.pc)(it->rep_, a...);
330+
r_ = (reinterpret_cast<call_type>(it->rep_->call_))(it->rep_, a...);
340331
}
341332
}
342333

@@ -369,20 +360,12 @@ struct signal_emit<void, void, T_arg...>
369360
signal_impl_holder exec(impl);
370361
const temp_slot_list slots(impl->slots_);
371362

372-
// Conversion between different types of function pointers with
373-
// reinterpret_cast can make gcc8 print a warning.
374-
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
375-
union {
376-
internal::hook ph;
377-
call_type pc;
378-
} u;
379363
for (const auto& slot : slots)
380364
{
381365
if (slot.empty() || slot.blocked())
382366
continue;
383367

384-
u.ph = slot.rep_->call_;
385-
(u.pc)(slot.rep_, a...);
368+
(reinterpret_cast<call_type>(slot.rep_->call_))(slot.rep_, a...);
386369
}
387370
}
388371
};

0 commit comments

Comments
 (0)