From db1b739943e9ea996105239573e3c38a50bf38cc Mon Sep 17 00:00:00 2001 From: kuzkry Date: Fri, 23 Aug 2019 11:57:56 -0400 Subject: Googletest export Merge b8ca465e73ac0954a0c9eec2a84bdd8913d5763b into 90a443f9c2437ca8a682a1ac625eba64e1d74a8a Closes #2396 COPYBARA_INTEGRATE_REVIEW=https://github.com/google/googletest/pull/2396 from kuzkry:custom-type-traits-true/false_type-and-bool_constant b8ca465e73ac0954a0c9eec2a84bdd8913d5763b PiperOrigin-RevId: 265064856 --- googlemock/include/gmock/gmock-matchers.h | 30 ++++++++++------------ .../include/gmock/internal/gmock-internal-utils.h | 21 ++++++--------- googlemock/test/gmock-internal-utils_test.cc | 15 ++++------- googletest/include/gtest/internal/gtest-internal.h | 2 +- googletest/include/gtest/internal/gtest-port.h | 11 ++------ 5 files changed, 29 insertions(+), 50 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 5fe3820..b1c0dc0 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -132,19 +132,16 @@ class MatcherCastImpl { // polymorphic_matcher_or_value to Matcher because it won't trigger // a user-defined conversion from M to T if one exists (assuming M is // a value). - return CastImpl( - polymorphic_matcher_or_value, - BooleanConstant< - std::is_convertible >::value>(), - BooleanConstant< - std::is_convertible::value>()); + return CastImpl(polymorphic_matcher_or_value, + bool_constant>::value>(), + bool_constant::value>()); } private: template static Matcher CastImpl(const M& polymorphic_matcher_or_value, - BooleanConstant /* convertible_to_matcher */, - BooleanConstant) { + bool_constant /* convertible_to_matcher */, + bool_constant) { // M is implicitly convertible to Matcher, which means that either // M is a polymorphic matcher or Matcher has an implicit constructor // from M. In both cases using the implicit conversion will produce a @@ -159,9 +156,9 @@ class MatcherCastImpl { // M can't be implicitly converted to Matcher, so M isn't a polymorphic // matcher. It's a value of a type implicitly convertible to T. Use direct // initialization to create a matcher. - static Matcher CastImpl( - const M& value, BooleanConstant /* convertible_to_matcher */, - BooleanConstant /* convertible_to_T */) { + static Matcher CastImpl(const M& value, + bool_constant /* convertible_to_matcher */, + bool_constant /* convertible_to_T */) { return Matcher(ImplicitCast_(value)); } @@ -175,9 +172,9 @@ class MatcherCastImpl { // (e.g. std::pair vs. std::pair). // // We don't define this method inline as we need the declaration of Eq(). - static Matcher CastImpl( - const M& value, BooleanConstant /* convertible_to_matcher */, - BooleanConstant /* convertible_to_T */); + static Matcher CastImpl(const M& value, + bool_constant /* convertible_to_matcher */, + bool_constant /* convertible_to_T */); }; // This more specialized version is used when MatcherCast()'s argument @@ -3603,9 +3600,8 @@ inline Matcher An() { return A(); } template Matcher internal::MatcherCastImpl::CastImpl( - const M& value, - internal::BooleanConstant /* convertible_to_matcher */, - internal::BooleanConstant /* convertible_to_T */) { + const M& value, internal::bool_constant /* convertible_to_matcher */, + internal::bool_constant /* convertible_to_T */) { return Eq(value); } diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index 5386f48..cea8ef6 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -170,27 +170,27 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint); // From, and kToKind is the kind of To; the value is // implementation-defined when the above pre-condition is violated. template -struct LosslessArithmeticConvertibleImpl : public false_type {}; +struct LosslessArithmeticConvertibleImpl : public std::false_type {}; // Converting bool to bool is lossless. template <> struct LosslessArithmeticConvertibleImpl - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting bool to any integer type is lossless. template struct LosslessArithmeticConvertibleImpl - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting bool to any floating-point type is lossless. template struct LosslessArithmeticConvertibleImpl - : public true_type {}; // NOLINT + : public std::true_type {}; // Converting an integer to bool is lossy. template struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting an integer to another non-bool integer is lossless if // the target type's range encloses the source type's range. @@ -211,17 +211,17 @@ struct LosslessArithmeticConvertibleImpl // the format of a floating-point number is implementation-defined. template struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to bool is lossy. template struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to an integer is lossy. template struct LosslessArithmeticConvertibleImpl - : public false_type {}; // NOLINT + : public std::false_type {}; // Converting a floating-point to another floating-point is lossless // if the target type is at least as big as the source type. @@ -470,11 +470,6 @@ struct RemoveConstFromKey > { typedef std::pair type; }; -// Mapping from booleans to types. Similar to boost::bool_ and -// std::integral_constant. -template -struct BooleanConstant {}; - // Emit an assertion failure due to incorrect DoDefault() usage. Out-of-lined to // reduce code size. GTEST_API_ void IllegalDoDefault(const char* file, int line); diff --git a/googlemock/test/gmock-internal-utils_test.cc b/googlemock/test/gmock-internal-utils_test.cc index 67865c2..67b7077 100644 --- a/googlemock/test/gmock-internal-utils_test.cc +++ b/googlemock/test/gmock-internal-utils_test.cc @@ -33,17 +33,20 @@ // This file tests the internal utilities. #include "gmock/internal/gmock-internal-utils.h" + #include + #include #include -#include #include +#include #include #include + #include "gmock/gmock.h" #include "gmock/internal/gmock-port.h" -#include "gtest/gtest.h" #include "gtest/gtest-spi.h" +#include "gtest/gtest.h" // Indicates that this translation unit is part of Google Test's // implementation. It must come before gtest-internal-inl.h is @@ -505,14 +508,6 @@ TEST(LogTest, OnlyWarningsArePrintedWhenVerbosityIsInvalid) { #endif // GTEST_HAS_STREAM_REDIRECTION -TEST(TypeTraitsTest, true_type) { - EXPECT_TRUE(true_type::value); -} - -TEST(TypeTraitsTest, false_type) { - EXPECT_FALSE(false_type::value); -} - TEST(TypeTraitsTest, remove_reference) { EXPECT_TRUE((std::is_same::type>::value)); EXPECT_TRUE( diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 3313445..37daf21 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -946,7 +946,7 @@ template -struct IsRecursiveContainerImpl : public false_type {}; +struct IsRecursiveContainerImpl : public std::false_type {}; // Since the IsRecursiveContainerImpl depends on the IsContainerTest we need to // obey the same inconsistencies as the IsContainerTest, namely check if diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index eaa1970..a637602 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -1898,15 +1898,8 @@ class GTEST_API_ ThreadLocal { // we cannot detect it. GTEST_API_ size_t GetThreadCount(); -template -struct bool_constant { - typedef bool_constant type; - static const bool value = bool_value; -}; -template const bool bool_constant::value; - -typedef bool_constant false_type; -typedef bool_constant true_type; +template +using bool_constant = std::integral_constant; template struct IteratorTraits { -- cgit v0.12