From 364839ab142e5d6e4efc89953e0911267d7c5502 Mon Sep 17 00:00:00 2001 From: Krystian Kuzniarek Date: Tue, 13 Aug 2019 23:59:59 +0200 Subject: remove a custom implementation of std::remove_const --- googlemock/include/gmock/gmock-matchers.h | 37 +++++++++++----------- .../include/gmock/internal/gmock-internal-utils.h | 10 +++--- googletest/include/gtest/internal/gtest-internal.h | 23 +------------- googletest/test/gtest_unittest.cc | 31 ++---------------- 4 files changed, 27 insertions(+), 74 deletions(-) diff --git a/googlemock/include/gmock/gmock-matchers.h b/googlemock/include/gmock/gmock-matchers.h index 7075082..7185390 100644 --- a/googlemock/include/gmock/gmock-matchers.h +++ b/googlemock/include/gmock/gmock-matchers.h @@ -1610,8 +1610,9 @@ class PointeeMatcher { template class Impl : public MatcherInterface { public: - typedef typename PointeeOf::type Pointee; + typedef + typename PointeeOf::type>::type Pointee; explicit Impl(const InnerMatcher& matcher) : matcher_(MatcherCast(matcher)) {} @@ -1749,8 +1750,8 @@ class FieldMatcher { // FIXME: The dispatch on std::is_pointer was introduced as a workaround for // a compiler bug, and can now be removed. return MatchAndExplainImpl( - typename std::is_pointer::type(), value, - listener); + typename std::is_pointer::type>::type(), + value, listener); } private: @@ -1816,8 +1817,8 @@ class PropertyMatcher { template bool MatchAndExplain(const T&value, MatchResultListener* listener) const { return MatchAndExplainImpl( - typename std::is_pointer::type(), value, - listener); + typename std::is_pointer::type>::type(), + value, listener); } private: @@ -2093,9 +2094,8 @@ class ContainerEqMatcher { template bool MatchAndExplain(const LhsContainer& lhs, MatchResultListener* listener) const { - // GTEST_REMOVE_CONST_() is needed to work around an MSVC 8.0 bug - // that causes LhsContainer to be a const type sometimes. - typedef internal::StlContainerView + typedef internal::StlContainerView< + typename std::remove_const::type> LhsView; typedef typename LhsView::type LhsStlContainer; StlContainerReference lhs_stl_container = LhsView::ConstReference(lhs); @@ -4034,12 +4034,12 @@ BeginEndDistanceIs(const DistanceMatcher& distance_matcher) { // values that are included in one container but not the other. (Duplicate // values and order differences are not explained.) template -inline PolymorphicMatcher > - ContainerEq(const Container& rhs) { +inline PolymorphicMatcher::type>> +ContainerEq(const Container& rhs) { // This following line is for working around a bug in MSVC 8.0, // which causes Container to be a const type sometimes. - typedef GTEST_REMOVE_CONST_(Container) RawContainer; + typedef typename std::remove_const::type RawContainer; return MakePolymorphicMatcher( internal::ContainerEqMatcher(rhs)); } @@ -4072,12 +4072,12 @@ WhenSorted(const ContainerMatcher& container_matcher) { // LHS container and the RHS container respectively. template inline internal::PointwiseMatcher + typename std::remove_const::type> Pointwise(const TupleMatcher& tuple_matcher, const Container& rhs) { // This following line is for working around a bug in MSVC 8.0, // which causes Container to be a const type sometimes (e.g. when // rhs is a const int[]).. - typedef GTEST_REMOVE_CONST_(Container) RawContainer; + typedef typename std::remove_const::type RawContainer; return internal::PointwiseMatcher( tuple_matcher, rhs); } @@ -4105,14 +4105,15 @@ inline internal::PointwiseMatcher > Pointwise( template inline internal::UnorderedElementsAreArrayMatcher< typename internal::BoundSecondMatcher< - Tuple2Matcher, typename internal::StlContainerView::type::value_type> > + Tuple2Matcher, + typename internal::StlContainerView< + typename std::remove_const::type>::type::value_type>> UnorderedPointwise(const Tuple2Matcher& tuple2_matcher, const RhsContainer& rhs_container) { // This following line is for working around a bug in MSVC 8.0, // which causes RhsContainer to be a const type sometimes (e.g. when // rhs_container is a const int[]). - typedef GTEST_REMOVE_CONST_(RhsContainer) RawRhsContainer; + typedef typename std::remove_const::type RawRhsContainer; // RhsView allows the same code to handle RhsContainer being a // STL-style container and it being a native C-style array. diff --git a/googlemock/include/gmock/internal/gmock-internal-utils.h b/googlemock/include/gmock/internal/gmock-internal-utils.h index ee00479..4d75483 100644 --- a/googlemock/include/gmock/internal/gmock-internal-utils.h +++ b/googlemock/include/gmock/internal/gmock-internal-utils.h @@ -429,8 +429,8 @@ class StlContainerView { static const_reference ConstReference(const RawContainer& container) { // Ensures that RawContainer is not a const type. - testing::StaticAssertTypeEq(); + testing::StaticAssertTypeEq< + RawContainer, typename std::remove_const::type>(); return container; } static type Copy(const RawContainer& container) { return container; } @@ -440,7 +440,7 @@ class StlContainerView { template class StlContainerView { public: - typedef GTEST_REMOVE_CONST_(Element) RawElement; + typedef typename std::remove_const::type RawElement; typedef internal::NativeArray type; // NativeArray can represent a native array either by value or by // reference (selected by a constructor argument), so 'const type' @@ -464,8 +464,8 @@ class StlContainerView { template class StlContainerView< ::std::tuple > { public: - typedef GTEST_REMOVE_CONST_( - typename internal::PointeeOf::type) RawElement; + typedef typename std::remove_const< + typename internal::PointeeOf::type>::type RawElement; typedef internal::NativeArray type; typedef const type const_reference; diff --git a/googletest/include/gtest/internal/gtest-internal.h b/googletest/include/gtest/internal/gtest-internal.h index 08531d8..af7cd33 100644 --- a/googletest/include/gtest/internal/gtest-internal.h +++ b/googletest/include/gtest/internal/gtest-internal.h @@ -869,30 +869,9 @@ struct RemoveReference { typedef T type; }; // NOLINT #define GTEST_REMOVE_REFERENCE_(T) \ typename ::testing::internal::RemoveReference::type -// Removes const from a type if it is a const type, otherwise leaves -// it unchanged. This is the same as tr1::remove_const, which is not -// widely available yet. -template -struct RemoveConst { typedef T type; }; // NOLINT -template -struct RemoveConst { typedef T type; }; // NOLINT - -// MSVC 8.0, Sun C++, and IBM XL C++ have a bug which causes the above -// definition to fail to remove the const in 'const int[3]' and 'const -// char[3][4]'. The following specialization works around the bug. -template -struct RemoveConst { - typedef typename RemoveConst::type type[N]; -}; - -// A handy wrapper around RemoveConst that works when the argument -// T depends on template parameters. -#define GTEST_REMOVE_CONST_(T) \ - typename ::testing::internal::RemoveConst::type - // Turns const U&, U&, const U, and U all into U. #define GTEST_REMOVE_REFERENCE_AND_CONST_(T) \ - GTEST_REMOVE_CONST_(GTEST_REMOVE_REFERENCE_(T)) + typename std::remove_const::type // IsAProtocolMessage::value is a compile-time bool constant that's // true if T is type proto2::Message or a subclass of it. diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 2b00b70..0047f53 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc @@ -61,9 +61,10 @@ TEST(CommandLineFlagsTest, CanBeAccessedInCodeOnceGTestHIsIncluded) { #include #include -#include #include +#include #include +#include #include "gtest/gtest-spi.h" #include "src/gtest-internal-inl.h" @@ -262,7 +263,6 @@ using testing::internal::OsStackTraceGetterInterface; using testing::internal::ParseInt32Flag; using testing::internal::RelationToSourceCopy; using testing::internal::RelationToSourceReference; -using testing::internal::RemoveConst; using testing::internal::RemoveReference; using testing::internal::ShouldRunTestOnShard; using testing::internal::ShouldShard; @@ -7135,33 +7135,6 @@ TEST(RemoveReferenceTest, MacroVersion) { TestGTestRemoveReference(); } - -// Tests that RemoveConst does not affect non-const types. -TEST(RemoveConstTest, DoesNotAffectNonConstType) { - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); -} - -// Tests that RemoveConst removes const from const types. -TEST(RemoveConstTest, RemovesConst) { - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); - CompileAssertTypesEqual::type>(); -} - -// Tests GTEST_REMOVE_CONST_. - -template -void TestGTestRemoveConst() { - CompileAssertTypesEqual(); -} - -TEST(RemoveConstTest, MacroVersion) { - TestGTestRemoveConst(); - TestGTestRemoveConst(); - TestGTestRemoveConst(); -} - // Tests GTEST_REMOVE_REFERENCE_AND_CONST_. template -- cgit v0.12