aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--odb/database.cxx2
-rw-r--r--odb/details/function-wrapper.hxx5
-rw-r--r--odb/details/function-wrapper.ixx10
-rw-r--r--odb/schema-catalog.cxx2
4 files changed, 17 insertions, 2 deletions
diff --git a/odb/database.cxx b/odb/database.cxx
index 7dd540f..f9e1043 100644
--- a/odb/database.cxx
+++ b/odb/database.cxx
@@ -67,7 +67,7 @@ namespace odb
else
{
typedef void (*caller) (const void*, const char*, connection_type&);
- reinterpret_cast<caller> (fw.function) (fw.std_function, name, c);
+ fw.cast<caller> () (fw.std_function, name, c);
}
return true;
diff --git a/odb/details/function-wrapper.hxx b/odb/details/function-wrapper.hxx
index 3a8ebfc..165df18 100644
--- a/odb/details/function-wrapper.hxx
+++ b/odb/details/function-wrapper.hxx
@@ -59,6 +59,11 @@ namespace odb
void swap (function_wrapper<F>&);
+ // Cleanly cast to an incompatible function type.
+ //
+ template <typename R> R
+ cast () const;
+
// Conversion to bool.
//
public:
diff --git a/odb/details/function-wrapper.ixx b/odb/details/function-wrapper.ixx
index d73d578..9ec19ec 100644
--- a/odb/details/function-wrapper.ixx
+++ b/odb/details/function-wrapper.ixx
@@ -36,5 +36,15 @@ namespace odb
swap (const_cast<function_wrapper<F>&> (x));
return *this;
}
+
+ template <typename F>
+ template <typename R>
+ inline R function_wrapper<F>::
+ cast () const
+ {
+ union { F* f; R r; } r;
+ r.f = function;
+ return r.r;
+ }
}
}
diff --git a/odb/schema-catalog.cxx b/odb/schema-catalog.cxx
index b767bca..946884f 100644
--- a/odb/schema-catalog.cxx
+++ b/odb/schema-catalog.cxx
@@ -227,7 +227,7 @@ namespace odb
else
{
typedef void (*caller) (const void*, database&);
- reinterpret_cast<caller> (m.function) (m.std_function, db);
+ m.cast<caller> () (m.std_function, db);
}
r++;
}