@@ -63,7 +63,7 @@ FOR(1, $1,[
63
63
inline T_return operator()(LOOP(arg%1_type_ _A_a%1, $1 )) const
64
64
{
65
65
if (!empty() && !blocked())
66
- return (sigc::internal::bitwise_equivalent_cast <call_type>(slot_base::rep_->call_))(LIST(slot_base::rep_, LOOP(_A_a%1, $1 )));
66
+ return (sigc::internal::function_pointer_cast <call_type>(slot_base::rep_->call_))(LIST(slot_base::rep_, LOOP(_A_a%1, $1 )));
67
67
return T_return();
68
68
}
69
69
@@ -355,7 +355,7 @@ ifelse($1,0,[
355
355
* @return A function pointer formed from call_it().
356
356
*/
357
357
static hook address()
358
- { return sigc::internal::bitwise_equivalent_cast <hook>(&call_it); }
358
+ { return sigc::internal::function_pointer_cast <hook>(&call_it); }
359
359
};
360
360
361
361
] )
@@ -381,25 +381,23 @@ namespace internal {
381
381
// Conversion between different types of function pointers with
382
382
// reinterpret_cast can make gcc8 print a warning.
383
383
// https://github.com/libsigcplusplus/libsigcplusplus/issues/1
384
- /** Returns the supplied bit pattern, interpreted as another type.
384
+ // https://github.com/libsigcplusplus/libsigcplusplus/issues/8
385
+ /** Returns the supplied function pointer, cast to a pointer to another function type.
385
386
*
386
- * When reinterpret_cast causes a compiler warning or error, this function
387
- * may work. Intended mainly for conversion between different types of pointers .
387
+ * When a single reinterpret_cast between function pointer types causes a
388
+ * compiler warning or error, this function may work .
388
389
*
389
- * Qualify calls with namespace names: sigc::internal::bitwise_equivalent_cast <>().
390
+ * Qualify calls with namespace names: sigc::internal::function_pointer_cast <>().
390
391
* If you don't, indirect calls from another library that also contains a
391
- * bitwise_equivalent_cast <>() (perhaps glibmm), can be ambiguous due to ADL
392
+ * function_pointer_cast <>() (perhaps glibmm), can be ambiguous due to ADL
392
393
* (argument-dependent lookup).
393
394
*/
394
- template <typename out_type , typename in_type >
395
- inline out_type bitwise_equivalent_cast(in_type in)
395
+ template <typename T_out , typename T_in >
396
+ inline T_out function_pointer_cast(T_in in)
396
397
{
397
- union {
398
- in_type in;
399
- out_type out;
400
- } u;
401
- u.in = in;
402
- return u.out;
398
+ // The double reinterpret_cast suppresses a warning from gcc8 with the
399
+ // -Wcast-function-type option.
400
+ return reinterpret_cast<T_out>(reinterpret_cast<void (*)()>(in));
403
401
}
404
402
405
403
/** A typed slot_rep.
@@ -507,7 +505,7 @@ struct slot_call
507
505
* @return A function pointer formed from call_it().
508
506
*/
509
507
static hook address()
510
- { return sigc::internal::bitwise_equivalent_cast <hook>(&call_it); }
508
+ { return sigc::internal::function_pointer_cast <hook>(&call_it); }
511
509
};
512
510
513
511
/** Abstracts functor execution.
@@ -539,7 +537,7 @@ struct slot_call<T_functor, T_return>
539
537
* @return A function pointer formed from call_it().
540
538
*/
541
539
static hook address()
542
- { return sigc::internal::bitwise_equivalent_cast <hook>(&call_it); }
540
+ { return sigc::internal::function_pointer_cast <hook>(&call_it); }
543
541
};
544
542
545
543
} /* namespace internal */
@@ -599,7 +597,7 @@ public:
599
597
inline T_return operator()(type_trait_take_t<T_arg>... _A_a) const
600
598
{
601
599
if (!empty() && !blocked())
602
- return (sigc::internal::bitwise_equivalent_cast <call_type>(slot_base::rep_->call_))(slot_base::rep_, _A_a...);
600
+ return (sigc::internal::function_pointer_cast <call_type>(slot_base::rep_->call_))(slot_base::rep_, _A_a...);
603
601
return T_return();
604
602
}
605
603
0 commit comments