Index: base/callback_internal.h |
diff --git a/base/callback_internal.h b/base/callback_internal.h |
index 8b79023b5a7cefc8e6cb7bd22d3fbd4e23e11315..e4e538ff15c2d0dfe239bc5d8b17fe411c59926e 100644 |
--- a/base/callback_internal.h |
+++ b/base/callback_internal.h |
@@ -129,7 +129,16 @@ |
// http://connect.microsoft.com/VisualStudio/feedbackdetail/view/957801/compilation-error-with-variadic-templates |
// |
// This is a typetraits object that's used to take an argument type, and |
-// extract a suitable type for forwarding arguments. |
+// extract a suitable type for storing and forwarding arguments. |
+// |
+// In particular, it strips off references, and converts arrays to |
+// pointers for storage; and it avoids accidentally trying to create a |
+// "reference of a reference" if the argument is a reference type. |
+// |
+// This array type becomes an issue for storage because we are passing bound |
+// parameters by const reference. In this case, we end up passing an actual |
+// array type in the initializer list which C++ does not allow. This will |
+// break passing of C-string literals. |
template <typename T> |
struct CallbackParamTraits |
: std::conditional<IsMoveOnlyType<T>::value, |
@@ -140,6 +149,18 @@ |
template <typename T> |
struct CallbackParamTraitsForNonMoveOnlyType { |
using ForwardType = const T&; |
+ using StorageType = T; |
+}; |
+ |
+// The Storage should almost be impossible to trigger unless someone manually |
+// specifies type of the bind parameters. However, in case they do, |
+// this will guard against us accidentally storing a reference parameter. |
+// |
+// The ForwardType should only be used for unbound arguments. |
+template <typename T> |
+struct CallbackParamTraitsForNonMoveOnlyType<T&> { |
+ using ForwardType = T&; |
+ using StorageType = T; |
}; |
// Note that for array types, we implicitly add a const in the conversion. This |
@@ -150,12 +171,14 @@ |
template <typename T, size_t n> |
struct CallbackParamTraitsForNonMoveOnlyType<T[n]> { |
using ForwardType = const T*; |
+ using StorageType = const T*; |
}; |
// See comment for CallbackParamTraits<T[n]>. |
template <typename T> |
struct CallbackParamTraitsForNonMoveOnlyType<T[]> { |
using ForwardType = const T*; |
+ using StorageType = const T*; |
}; |
// Parameter traits for movable-but-not-copyable scopers. |
@@ -174,6 +197,7 @@ |
template <typename T> |
struct CallbackParamTraitsForMoveOnlyType { |
using ForwardType = T; |
+ using StorageType = T; |
}; |
// CallbackForward() is a very limited simulation of C++11's std::forward() |