Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(403)

Unified Diff: base/callback_internal.h

Issue 1654973003: Revert of Do Perfect Forwarding from base::Bind to BindState storage (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « base/bind_internal.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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()
« no previous file with comments | « base/bind_internal.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698