Remove base's implicit_cast.
There's no momentum on making this a thing in the C++ standard. We
should have less magic that is non-standard in base.
R=ricea@chromium.org, thakis@chromium.org, vmpstr
BUG=529769
Review URL: https://codereview.chromium.org/1340683002
Cr-Commit-Position: refs/heads/master@{#348978}
CrOS-Libchrome-Original-Commit: a5f0d96bc4f40971fc82e0b2255e27056d4621d1
diff --git a/base/android/scoped_java_ref.h b/base/android/scoped_java_ref.h
index 6d44195..cad63b7 100644
--- a/base/android/scoped_java_ref.h
+++ b/base/android/scoped_java_ref.h
@@ -11,6 +11,7 @@
#include "base/base_export.h"
#include "base/basictypes.h"
#include "base/logging.h"
+#include "base/template_util.h"
namespace base {
namespace android {
@@ -178,7 +179,8 @@
template<typename U>
void Reset(JNIEnv* env, U obj) {
- implicit_cast<T>(obj); // Ensure U is assignable to T
+ static_assert(base::is_convertible<U, T>::value,
+ "U must be convertible to T");
env_ = this->SetNewLocalRef(env, obj);
}
@@ -242,7 +244,8 @@
template<typename U>
void Reset(JNIEnv* env, U obj) {
- implicit_cast<T>(obj); // Ensure U is assignable to T
+ static_assert(base::is_convertible<U, T>::value,
+ "U must be convertible to T");
this->SetNewGlobalRef(env, obj);
}
diff --git a/base/files/file_unittest.cc b/base/files/file_unittest.cc
index 5c59424..3d60b2c 100644
--- a/base/files/file_unittest.cc
+++ b/base/files/file_unittest.cc
@@ -517,7 +517,7 @@
// Test that changing the checksum value is detected.
base::File file;
EXPECT_NE(file.file_.file_memory_checksum_,
- implicit_cast<unsigned int>(file.GetPlatformFile()));
+ static_cast<unsigned int>(file.GetPlatformFile()));
file.file_.file_memory_checksum_ = file.GetPlatformFile();
EXPECT_DEATH(file.IsValid(), "");
diff --git a/base/macros.h b/base/macros.h
index 53b3926..c5f503f 100644
--- a/base/macros.h
+++ b/base/macros.h
@@ -55,29 +55,6 @@
template <typename T, size_t N> char (&ArraySizeHelper(T (&array)[N]))[N];
#define arraysize(array) (sizeof(ArraySizeHelper(array)))
-
-// Use implicit_cast as a safe version of static_cast or const_cast
-// for upcasting in the type hierarchy (i.e. casting a pointer to Foo
-// to a pointer to SuperclassOfFoo or casting a pointer to Foo to
-// a const pointer to Foo).
-// When you use implicit_cast, the compiler checks that the cast is safe.
-// Such explicit implicit_casts are necessary in surprisingly many
-// situations where C++ demands an exact type match instead of an
-// argument type convertible to a target type.
-//
-// The From type can be inferred, so the preferred syntax for using
-// implicit_cast is the same as for static_cast etc.:
-//
-// implicit_cast<ToType>(expr)
-//
-// implicit_cast would have been part of the C++ standard library,
-// but the proposal was submitted too late. It will probably make
-// its way into the language in the future.
-template<typename To, typename From>
-inline To implicit_cast(From const &f) {
- return f;
-}
-
// The COMPILE_ASSERT macro can be used to verify that a compile time
// expression is true. For example, you could use it to verify the
// size of a static array:
diff --git a/base/memory/scoped_ptr.h b/base/memory/scoped_ptr.h
index 987ccfa..fb781b0 100644
--- a/base/memory/scoped_ptr.h
+++ b/base/memory/scoped_ptr.h
@@ -465,9 +465,7 @@
// (C++98 [expr.delete]p3). If you're doing this, fix your code.
// - it cannot be const-qualified differently from T per unique_ptr spec
// (http://cplusplus.github.com/LWG/lwg-active.html#2118). Users wanting
- // to work around this may use implicit_cast<const T*>().
- // However, because of the first bullet in this comment, users MUST
- // NOT use implicit_cast<Base*>() to upcast the static type of the array.
+ // to work around this may use const_cast<const T*>().
explicit scoped_ptr(element_type* array) : impl_(array) {}
// Constructor. Allows construction from a nullptr.
diff --git a/base/numerics/safe_numerics_unittest.cc b/base/numerics/safe_numerics_unittest.cc
index bad0f57..f2bb011 100644
--- a/base/numerics/safe_numerics_unittest.cc
+++ b/base/numerics/safe_numerics_unittest.cc
@@ -673,9 +673,9 @@
EXPECT_TRUE(IsValueInRangeForNumericType<int32_t>(
std::numeric_limits<int32_t>::min()));
EXPECT_TRUE(IsValueInRangeForNumericType<int32_t>(
- implicit_cast<int64_t>(std::numeric_limits<int32_t>::min())));
+ static_cast<int64_t>(std::numeric_limits<int32_t>::min())));
EXPECT_FALSE(IsValueInRangeForNumericType<int32_t>(
- implicit_cast<int64_t>(std::numeric_limits<int32_t>::min()) - 1));
+ static_cast<int64_t>(std::numeric_limits<int32_t>::min()) - 1));
EXPECT_FALSE(IsValueInRangeForNumericType<int32_t>(
std::numeric_limits<int64_t>::min()));
@@ -715,7 +715,7 @@
EXPECT_TRUE(IsValueInRangeForNumericType<int64_t>(
std::numeric_limits<int32_t>::min()));
EXPECT_TRUE(IsValueInRangeForNumericType<int64_t>(
- implicit_cast<int64_t>(std::numeric_limits<int32_t>::min())));
+ static_cast<int64_t>(std::numeric_limits<int32_t>::min())));
EXPECT_TRUE(IsValueInRangeForNumericType<int64_t>(
std::numeric_limits<int64_t>::min()));
}