X-Git-Url: http://review.tizen.org/git/?a=blobdiff_plain;f=googlemock%2Finclude%2Fgmock%2Finternal%2Fgmock-internal-utils.h;h=317544a7daf5da7ba9a28db1e991f071ef762960;hb=548497ee798bf6e0a300e2d9848109ea1265a56b;hp=fdc049c589cb9865c0cac8221693dcd3092b2d95;hpb=ea17aef41dec775b644330ec50fa99e945f6b308;p=platform%2Fupstream%2Fgtest.git diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index fdc049c..317544a 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -36,8 +36,8 @@ // GOOGLETEST_CM0002 DO NOT DELETE -#ifndef GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ -#define GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ +#ifndef GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ +#define GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ #include #include // NOLINT @@ -71,20 +71,6 @@ GTEST_API_ std::string JoinAsTuple(const Strings& fields); // "foo_bar_123" are converted to "foo bar 123". GTEST_API_ std::string ConvertIdentifierNameToWords(const char* id_name); -// PointeeOf::type is the type of a value pointed to by a -// Pointer, which can be either a smart pointer or a raw pointer. The -// following default implementation is for the case where Pointer is a -// smart pointer. -template -struct PointeeOf { - // Smart pointer classes define type element_type as the type of - // their pointees. - typedef typename Pointer::element_type type; -}; -// This specialization is for the raw pointer case. -template -struct PointeeOf { typedef T type; }; // NOLINT - // GetRawPointer(p) returns the raw pointer underlying p when p is a // smart pointer, or returns p itself when p is already a raw pointer. // The following default implementation is for the smart pointer case. @@ -136,15 +122,13 @@ GMOCK_DECLARE_KIND_(int, kInteger); GMOCK_DECLARE_KIND_(unsigned int, kInteger); GMOCK_DECLARE_KIND_(long, kInteger); // NOLINT GMOCK_DECLARE_KIND_(unsigned long, kInteger); // NOLINT +GMOCK_DECLARE_KIND_(long long, kInteger); // NOLINT +GMOCK_DECLARE_KIND_(unsigned long long, kInteger); // NOLINT #if GMOCK_WCHAR_T_IS_NATIVE_ GMOCK_DECLARE_KIND_(wchar_t, kInteger); #endif -// Non-standard integer types. -GMOCK_DECLARE_KIND_(Int64, kInteger); -GMOCK_DECLARE_KIND_(UInt64, kInteger); - // All standard floating-point types. GMOCK_DECLARE_KIND_(float, kFloatingPoint); GMOCK_DECLARE_KIND_(double, kFloatingPoint); @@ -157,9 +141,6 @@ GMOCK_DECLARE_KIND_(long double, kFloatingPoint); static_cast< ::testing::internal::TypeKind>( \ ::testing::internal::KindOf::value) -// Evaluates to true if and only if integer type T is signed. -#define GMOCK_IS_SIGNED_(T) (static_cast(-1) < 0) - // LosslessArithmeticConvertibleImpl::value // is true if and only if arithmetic type From can be losslessly converted to // arithmetic type To. @@ -170,65 +151,30 @@ 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 std::false_type {}; - -// Converting bool to bool is lossless. -template <> -struct LosslessArithmeticConvertibleImpl - : public std::true_type {}; - -// Converting bool to any integer type is lossless. -template -struct LosslessArithmeticConvertibleImpl - : public std::true_type {}; - -// Converting bool to any floating-point type is lossless. -template -struct LosslessArithmeticConvertibleImpl - : public std::true_type {}; - -// Converting an integer to bool is lossy. -template -struct LosslessArithmeticConvertibleImpl - : public std::false_type {}; - -// Converting an integer to another non-bool integer is lossless -// if and only if the target type's range encloses the source type's range. -template -struct LosslessArithmeticConvertibleImpl - : public bool_constant< - // When converting from a smaller size to a larger size, we are - // fine as long as we are not converting from signed to unsigned. - ((sizeof(From) < sizeof(To)) && - (!GMOCK_IS_SIGNED_(From) || GMOCK_IS_SIGNED_(To))) || - // When converting between the same size, the signedness must match. - ((sizeof(From) == sizeof(To)) && - (GMOCK_IS_SIGNED_(From) == GMOCK_IS_SIGNED_(To)))> {}; // NOLINT - -#undef GMOCK_IS_SIGNED_ - -// Converting an integer to a floating-point type may be lossy, since -// the format of a floating-point number is implementation-defined. -template -struct LosslessArithmeticConvertibleImpl - : public std::false_type {}; - -// Converting a floating-point to bool is lossy. -template -struct LosslessArithmeticConvertibleImpl - : public std::false_type {}; - -// Converting a floating-point to an integer is lossy. -template -struct LosslessArithmeticConvertibleImpl - : public std::false_type {}; - -// Converting a floating-point to another floating-point is lossless -// if and only if the target type is at least as big as the source type. -template -struct LosslessArithmeticConvertibleImpl< - kFloatingPoint, From, kFloatingPoint, To> - : public bool_constant {}; // NOLINT +using LosslessArithmeticConvertibleImpl = std::integral_constant< + bool, + // clang-format off + // Converting from bool is always lossless + (kFromKind == kBool) ? true + // Converting between any other type kinds will be lossy if the type + // kinds are not the same. + : (kFromKind != kToKind) ? false + : (kFromKind == kInteger && + // Converting between integers of different widths is allowed so long + // as the conversion does not go from signed to unsigned. + (((sizeof(From) < sizeof(To)) && + !(std::is_signed::value && !std::is_signed::value)) || + // Converting between integers of the same width only requires the + // two types to have the same signedness. + ((sizeof(From) == sizeof(To)) && + (std::is_signed::value == std::is_signed::value))) + ) ? true + // Floating point conversions are lossless if and only if `To` is at least + // as wide as `From`. + : (kFromKind == kFloatingPoint && (sizeof(From) <= sizeof(To))) ? true + : false + // clang-format on + >; // LosslessArithmeticConvertible::value is true if and only if // arithmetic type From can be losslessly converted to arithmetic type To. @@ -238,9 +184,9 @@ struct LosslessArithmeticConvertibleImpl< // reference) built-in arithmetic types; the value is // implementation-defined when the above pre-condition is violated. template -struct LosslessArithmeticConvertible - : public LosslessArithmeticConvertibleImpl< - GMOCK_KIND_OF_(From), From, GMOCK_KIND_OF_(To), To> {}; // NOLINT +using LosslessArithmeticConvertible = + LosslessArithmeticConvertibleImpl; // This interface knows how to report a Google Mock failure (either // non-fatal or fatal). @@ -334,8 +280,6 @@ class WithoutMatchers { // Internal use only: access the singleton instance of WithoutMatchers. GTEST_API_ WithoutMatchers GetWithoutMatchers(); -// Type traits. - // Disable MSVC warnings for infinite recursion, since in this case the // the recursion is unreachable. #ifdef _MSC_VER @@ -420,7 +364,8 @@ template class StlContainerView< ::std::tuple > { public: typedef typename std::remove_const< - typename internal::PointeeOf::type>::type RawElement; + typename std::pointer_traits::element_type>::type + RawElement; typedef internal::NativeArray type; typedef const type const_reference; @@ -464,11 +409,13 @@ auto ApplyImpl(F&& f, Tuple&& args, IndexSequence) -> decltype( // Apply the function to a tuple of arguments. template -auto Apply(F&& f, Tuple&& args) - -> decltype(ApplyImpl(std::forward(f), std::forward(args), - MakeIndexSequence::value>())) { +auto Apply(F&& f, Tuple&& args) -> decltype( + ApplyImpl(std::forward(f), std::forward(args), + MakeIndexSequence::type>::value>())) { return ApplyImpl(std::forward(f), std::forward(args), - MakeIndexSequence::value>()); + MakeIndexSequence::type>::value>()); } // Template struct Function, where F must be a function type, contains @@ -492,8 +439,7 @@ struct Function { using Result = R; static constexpr size_t ArgumentCount = sizeof...(Args); template - using Arg = ElemFromList::type, - Args...>; + using Arg = ElemFromList; using ArgumentTuple = std::tuple; using ArgumentMatcherTuple = std::tuple...>; using MakeResultVoid = void(Args...); @@ -510,4 +456,4 @@ constexpr size_t Function::ArgumentCount; } // namespace internal } // namespace testing -#endif // GMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_ +#endif // GOOGLEMOCK_INCLUDE_GMOCK_INTERNAL_GMOCK_INTERNAL_UTILS_H_