summaryrefslogtreecommitdiffstats
path: root/base/callback.h
diff options
context:
space:
mode:
authorajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-26 16:22:50 +0000
committerajwong@chromium.org <ajwong@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2011-06-26 16:22:50 +0000
commit6a341fbb4fa4651ea5d60ce8aa57e5fabe3da375 (patch)
tree1062e8ae71f9d3a15421809847e6b0208bde8ad0 /base/callback.h
parente93fd55e815c0004672e0a7621fcd617b8196035 (diff)
downloadchromium_src-6a341fbb4fa4651ea5d60ce8aa57e5fabe3da375.zip
chromium_src-6a341fbb4fa4651ea5d60ce8aa57e5fabe3da375.tar.gz
chromium_src-6a341fbb4fa4651ea5d60ce8aa57e5fabe3da375.tar.bz2
Add COMPILE_ASSERT to ensure the result of Bind matches the Callback's type.
Required because we abstract the storage of the funciton pointer out using a reinterpret_cast to reduce template bloat. This effectively readds the failure that would have happened had we stored the function pointer directly in the template class. BUG=86008 TEST=new unittests. Review URL: http://codereview.chromium.org/7241015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@90525 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'base/callback.h')
-rw-r--r--base/callback.h22
1 files changed, 22 insertions, 0 deletions
diff --git a/base/callback.h b/base/callback.h
index 7f9b548..c1f584d 100644
--- a/base/callback.h
+++ b/base/callback.h
@@ -13,6 +13,7 @@
#pragma once
#include "base/callback_internal.h"
+#include "base/template_util.h"
// New, super-duper, unified Callback system. This will eventually replace
// NewRunnableMethod, NewRunnableFunction, CreateFunctor, and CreateCallback
@@ -252,6 +253,9 @@ class Callback<R(void)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run() const {
@@ -283,6 +287,9 @@ class Callback<R(A1)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run(typename internal::ParamTraits<A1>::ForwardType a1) const {
@@ -315,6 +322,9 @@ class Callback<R(A1, A2)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run(typename internal::ParamTraits<A1>::ForwardType a1,
@@ -350,6 +360,9 @@ class Callback<R(A1, A2, A3)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run(typename internal::ParamTraits<A1>::ForwardType a1,
@@ -388,6 +401,9 @@ class Callback<R(A1, A2, A3, A4)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run(typename internal::ParamTraits<A1>::ForwardType a1,
@@ -430,6 +446,9 @@ class Callback<R(A1, A2, A3, A4, A5)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run(typename internal::ParamTraits<A1>::ForwardType a1,
@@ -475,6 +494,9 @@ class Callback<R(A1, A2, A3, A4, A5, A6)> : public internal::CallbackBase {
: CallbackBase(
reinterpret_cast<InvokeFuncStorage>(&T::Invoker::DoInvoke),
&invoker_holder.invoker_storage_) {
+ COMPILE_ASSERT((is_same<PolymorphicInvoke,
+ typename T::Invoker::DoInvokeType>::value),
+ callback_type_does_not_match_bind_result);
}
R Run(typename internal::ParamTraits<A1>::ForwardType a1,