aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLuis Hector Chavez <lhchavez@google.com>2016-05-20 23:02:44 -0700
committerLuis Hector Chavez <lhchavez@google.com>2016-05-26 16:23:31 -0700
commit1d8db72ddabfe39e43b6b25a00023d22748d2044 (patch)
treea67eae2fbdc88e17651174774da21a50231eeae7
parent55cc0e85b97b656885aaab8d5688ff9b32bc7e88 (diff)
downloadgtest-1d8db72ddabfe39e43b6b25a00023d22748d2044.tar.gz
gtest: Add support for std::unique_ptr bool conversion
This cherry-picks the new AssertionResult constructor that supports contextual conversion to bool, found in https://github.com/google/googletest/commit/8120f66c3249e253f03fdb48bee7e528bc038d31 This is needed to support a libchrome uprev. BUG: 28985443 TEST: All tests in libchrome_test pass on dragonboard-eng build Change-Id: I59bc96f785e97a1c6abfa492f72278cb99213303
-rw-r--r--include/gtest/gtest.h15
-rw-r--r--include/gtest/internal/gtest-internal.h2
2 files changed, 15 insertions, 2 deletions
diff --git a/include/gtest/gtest.h b/include/gtest/gtest.h
index 6fa0a39..8f310a6 100644
--- a/include/gtest/gtest.h
+++ b/include/gtest/gtest.h
@@ -258,8 +258,21 @@ class GTEST_API_ AssertionResult {
// Copy constructor.
// Used in EXPECT_TRUE/FALSE(assertion_result).
AssertionResult(const AssertionResult& other);
+
// Used in the EXPECT_TRUE/FALSE(bool_expression).
- explicit AssertionResult(bool success) : success_(success) {}
+ //
+ // T must be contextually convertible to bool.
+ //
+ // The second parameter prevents this overload from being considered if
+ // the argument is implicitly convertible to AssertionResult. In that case
+ // we want AssertionResult's copy constructor to be used.
+ template <typename T>
+ explicit AssertionResult(
+ const T& success,
+ typename internal::EnableIf<
+ !internal::ImplicitlyConvertible<T, AssertionResult>::value>::type*
+ /*enabler*/ = NULL)
+ : success_(success) {}
// Returns true iff the assertion succeeded.
operator bool() const { return success_; } // NOLINT
diff --git a/include/gtest/internal/gtest-internal.h b/include/gtest/internal/gtest-internal.h
index 0dcc3a3..f58f65f 100644
--- a/include/gtest/internal/gtest-internal.h
+++ b/include/gtest/internal/gtest-internal.h
@@ -784,7 +784,7 @@ class ImplicitlyConvertible {
// MakeFrom() is an expression whose type is From. We cannot simply
// use From(), as the type From may not have a public default
// constructor.
- static From MakeFrom();
+ static typename AddReference<From>::type MakeFrom();
// These two functions are overloaded. Given an expression
// Helper(x), the compiler will pick the first version if x can be