Skip to content

Commit 7a0680d

Browse files
committed
Merge pull request #1959 from robinlinden:remove-msvc-workarounds
PiperOrigin-RevId: 221356626
2 parents b18d39b + 4802133 commit 7a0680d

File tree

10 files changed

+21
-102
lines changed

10 files changed

+21
-102
lines changed

googlemock/include/gmock/gmock-matchers.h

-7
Original file line numberDiff line numberDiff line change
@@ -2485,15 +2485,8 @@ class PropertyMatcher {
24852485
*listener << whose_property_ << "is ";
24862486
// Cannot pass the return value (for example, int) to MatchPrintAndExplain,
24872487
// which takes a non-const reference as argument.
2488-
#if defined(_PREFAST_ ) && _MSC_VER == 1800
2489-
// Workaround bug in VC++ 2013's /analyze parser.
2490-
// https://connect.microsoft.com/VisualStudio/feedback/details/1106363/internal-compiler-error-with-analyze-due-to-failure-to-infer-move
2491-
posix::Abort(); // To make sure it is never run.
2492-
return false;
2493-
#else
24942488
RefToConstProperty result = (obj.*property_)();
24952489
return MatchPrintAndExplain(result, matcher_, listener);
2496-
#endif
24972490
}
24982491

24992492
bool MatchAndExplainImpl(true_type /* is_pointer */, const Class* p,

googlemock/include/gmock/internal/gmock-port.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -55,10 +55,10 @@
5555
#include "gtest/internal/gtest-port.h"
5656
#include "gmock/internal/custom/gmock-port.h"
5757

58-
// For MS Visual C++, check the compiler version. At least VS 2003 is
58+
// For MS Visual C++, check the compiler version. At least VS 2015 is
5959
// required to compile Google Mock.
60-
#if defined(_MSC_VER) && _MSC_VER < 1310
61-
# error "At least Visual C++ 2003 (7.1) is required to compile Google Mock."
60+
#if defined(_MSC_VER) && _MSC_VER < 1900
61+
# error "At least Visual C++ 2015 (14.0) is required to compile Google Mock."
6262
#endif
6363

6464
// Macro for referencing flags. This is public as we want the user to

googlemock/src/gmock-spec-builders.cc

+3-3
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,9 @@
5050
#endif
5151

5252
// Silence C4800 (C4800: 'int *const ': forcing value
53-
// to bool 'true' or 'false') for MSVC 14,15
53+
// to bool 'true' or 'false') for MSVC 15
5454
#ifdef _MSC_VER
55-
#if _MSC_VER <= 1900
55+
#if _MSC_VER == 1900
5656
# pragma warning(push)
5757
# pragma warning(disable:4800)
5858
#endif
@@ -887,7 +887,7 @@ InSequence::~InSequence() {
887887
} // namespace testing
888888

889889
#ifdef _MSC_VER
890-
#if _MSC_VER <= 1900
890+
#if _MSC_VER == 1900
891891
# pragma warning(pop)
892892
#endif
893893
#endif

googlemock/test/gmock-actions_test.cc

+2-2
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,9 @@
3333
// This file tests the built-in actions.
3434

3535
// Silence C4800 (C4800: 'int *const ': forcing value
36-
// to bool 'true' or 'false') for MSVC 14,15
36+
// to bool 'true' or 'false') for MSVC 15
3737
#ifdef _MSC_VER
38-
#if _MSC_VER <= 1900
38+
#if _MSC_VER == 1900
3939
# pragma warning(push)
4040
# pragma warning(disable:4800)
4141
#endif

googlemock/test/gmock-generated-function-mockers_test.cc

-14
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,6 @@
4646
#include "gmock/gmock.h"
4747
#include "gtest/gtest.h"
4848

49-
// There is a bug in MSVC (fixed in VS 2008) that prevents creating a
50-
// mock for a function with const arguments, so we don't test such
51-
// cases for MSVC versions older than 2008.
52-
#if !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
53-
# define GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
54-
#endif // !GTEST_OS_WINDOWS || (_MSC_VER >= 1500)
55-
5649
namespace testing {
5750
namespace gmock_generated_function_mockers_test {
5851

@@ -85,9 +78,7 @@ class FooInterface {
8578

8679
virtual bool TakesNonConstReference(int& n) = 0; // NOLINT
8780
virtual std::string TakesConstReference(const int& n) = 0;
88-
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
8981
virtual bool TakesConst(const int x) = 0;
90-
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
9182

9283
virtual int OverloadedOnArgumentNumber() = 0;
9384
virtual int OverloadedOnArgumentNumber(int n) = 0;
@@ -136,10 +127,7 @@ class MockFoo : public FooInterface {
136127

137128
MOCK_METHOD1(TakesNonConstReference, bool(int&)); // NOLINT
138129
MOCK_METHOD1(TakesConstReference, std::string(const int&));
139-
140-
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
141130
MOCK_METHOD1(TakesConst, bool(const int)); // NOLINT
142-
#endif
143131

144132
// Tests that the function return type can contain unprotected comma.
145133
MOCK_METHOD0(ReturnTypeWithComma, std::map<int, std::string>());
@@ -249,15 +237,13 @@ TEST_F(FunctionMockerTest, MocksFunctionWithConstReferenceArgument) {
249237
EXPECT_EQ("Hello", foo_->TakesConstReference(a));
250238
}
251239

252-
#ifdef GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
253240
// Tests mocking a function that takes a const variable.
254241
TEST_F(FunctionMockerTest, MocksFunctionWithConstArgument) {
255242
EXPECT_CALL(mock_foo_, TakesConst(Lt(10)))
256243
.WillOnce(DoDefault());
257244

258245
EXPECT_FALSE(foo_->TakesConst(5));
259246
}
260-
#endif // GMOCK_ALLOWS_CONST_PARAM_FUNCTIONS
261247

262248
// Tests mocking functions overloaded on the number of arguments.
263249
TEST_F(FunctionMockerTest, MocksFunctionsOverloadedOnArgumentNumber) {

googletest/cmake/internal_utils.cmake

+4-26
Original file line numberDiff line numberDiff line change
@@ -68,36 +68,14 @@ macro(config_compiler_and_linker)
6868
# Newlines inside flags variables break CMake's NMake generator.
6969
# TODO([email protected]): Add -RTCs and -RTCu to debug builds.
7070
set(cxx_base_flags "-GS -W4 -WX -wd4251 -wd4275 -nologo -J -Zi")
71-
if (MSVC_VERSION LESS 1400) # 1400 is Visual Studio 2005
72-
# Suppress spurious warnings MSVC 7.1 sometimes issues.
73-
# Forcing value to bool.
74-
set(cxx_base_flags "${cxx_base_flags} -wd4800")
75-
# Copy constructor and assignment operator could not be generated.
76-
set(cxx_base_flags "${cxx_base_flags} -wd4511 -wd4512")
77-
# Compatibility warnings not applicable to Google Test.
78-
# Resolved overload was found by argument-dependent lookup.
79-
set(cxx_base_flags "${cxx_base_flags} -wd4675")
80-
endif()
81-
if (MSVC_VERSION LESS 1500) # 1500 is Visual Studio 2008
82-
# Conditional expression is constant.
83-
# When compiling with /W4, we get several instances of C4127
84-
# (Conditional expression is constant). In our code, we disable that
85-
# warning on a case-by-case basis. However, on Visual Studio 2005,
86-
# the warning fires on std::list. Therefore on that compiler and earlier,
87-
# we disable the warning project-wide.
88-
set(cxx_base_flags "${cxx_base_flags} -wd4127")
89-
endif()
90-
if (NOT (MSVC_VERSION LESS 1700)) # 1700 is Visual Studio 2012.
91-
# Suppress "unreachable code" warning on VS 2012 and later.
92-
# http://stackoverflow.com/questions/3232669 explains the issue.
93-
set(cxx_base_flags "${cxx_base_flags} -wd4702")
94-
endif()
95-
9671
set(cxx_base_flags "${cxx_base_flags} -D_UNICODE -DUNICODE -DWIN32 -D_WIN32")
9772
set(cxx_base_flags "${cxx_base_flags} -DSTRICT -DWIN32_LEAN_AND_MEAN")
9873
set(cxx_exception_flags "-EHsc -D_HAS_EXCEPTIONS=1")
9974
set(cxx_no_exception_flags "-EHs-c- -D_HAS_EXCEPTIONS=0")
10075
set(cxx_no_rtti_flags "-GR-")
76+
# Suppress "unreachable code" warning
77+
# http://stackoverflow.com/questions/3232669 explains the issue.
78+
set(cxx_base_flags "${cxx_base_flags} -wd4702")
10179
elseif (CMAKE_COMPILER_IS_GNUCXX)
10280
set(cxx_base_flags "-Wall -Wshadow -Werror")
10381
if(NOT CMAKE_CXX_COMPILER_VERSION VERSION_LESS 7.0.0)
@@ -219,7 +197,7 @@ endfunction()
219197
# is built from the given source files with the given compiler flags.
220198
function(cxx_executable_with_flags name cxx_flags libs)
221199
add_executable(${name} ${ARGN})
222-
if (MSVC AND (NOT (MSVC_VERSION LESS 1700))) # 1700 is Visual Studio 2012.
200+
if (MSVC)
223201
# BigObj required for tests.
224202
set(cxx_flags "${cxx_flags} -bigobj")
225203
endif()

googletest/include/gtest/internal/gtest-internal.h

-10
Original file line numberDiff line numberDiff line change
@@ -840,16 +840,6 @@ struct RemoveConst<const T[N]> {
840840
typedef typename RemoveConst<T>::type type[N];
841841
};
842842

843-
#if defined(_MSC_VER) && _MSC_VER < 1400
844-
// This is the only specialization that allows VC++ 7.1 to remove const in
845-
// 'const int[3] and 'const int[3][4]'. However, it causes trouble with GCC
846-
// and thus needs to be conditionally compiled.
847-
template <typename T, size_t N>
848-
struct RemoveConst<T[N]> {
849-
typedef typename RemoveConst<T>::type type[N];
850-
};
851-
#endif
852-
853843
// A handy wrapper around RemoveConst that works when the argument
854844
// T depends on template parameters.
855845
#define GTEST_REMOVE_CONST_(T) \

googletest/include/gtest/internal/gtest-port.h

+6-18
Original file line numberDiff line numberDiff line change
@@ -304,14 +304,14 @@
304304
// GTEST_DISABLE_MSC_WARNINGS_PUSH_(4800 4385)
305305
// /* code that triggers warnings C4800 and C4385 */
306306
// GTEST_DISABLE_MSC_WARNINGS_POP_()
307-
#if _MSC_VER >= 1400
307+
#if defined(_MSC_VER)
308308
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings) \
309309
__pragma(warning(push)) \
310310
__pragma(warning(disable: warnings))
311311
# define GTEST_DISABLE_MSC_WARNINGS_POP_() \
312312
__pragma(warning(pop))
313313
#else
314-
// Older versions of MSVC don't have __pragma.
314+
// Not all compilers are MSVC
315315
# define GTEST_DISABLE_MSC_WARNINGS_PUSH_(warnings)
316316
# define GTEST_DISABLE_MSC_WARNINGS_POP_()
317317
#endif
@@ -602,15 +602,6 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
602602
# include <time.h> // NOLINT
603603
#endif
604604

605-
// Determines if hash_map/hash_set are available.
606-
// Only used for testing against those containers.
607-
#if !defined(GTEST_HAS_HASH_MAP_)
608-
# if defined(_MSC_VER) && (_MSC_VER < 1900)
609-
# define GTEST_HAS_HASH_MAP_ 1 // Indicates that hash_map is available.
610-
# define GTEST_HAS_HASH_SET_ 1 // Indicates that hash_set is available.
611-
# endif // _MSC_VER
612-
#endif // !defined(GTEST_HAS_HASH_MAP_)
613-
614605
// Determines whether clone(2) is supported.
615606
// Usually it will only be available on Linux, excluding
616607
// Linux on the Itanium architecture.
@@ -653,12 +644,10 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
653644
#endif // GTEST_HAS_STREAM_REDIRECTION
654645

655646
// Determines whether to support death tests.
656-
// Google Test does not support death tests for VC 7.1 and earlier as
657-
// abort() in a VC 7.1 application compiled as GUI in debug config
658647
// pops up a dialog window that cannot be suppressed programmatically.
659648
#if (GTEST_OS_LINUX || GTEST_OS_CYGWIN || GTEST_OS_SOLARIS || \
660649
(GTEST_OS_MAC && !GTEST_OS_IOS) || \
661-
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER >= 1400) || \
650+
(GTEST_OS_WINDOWS_DESKTOP && _MSC_VER) || \
662651
GTEST_OS_WINDOWS_MINGW || GTEST_OS_AIX || GTEST_OS_HPUX || \
663652
GTEST_OS_OPENBSD || GTEST_OS_QNX || GTEST_OS_FREEBSD || \
664653
GTEST_OS_NETBSD || GTEST_OS_FUCHSIA)
@@ -669,7 +658,7 @@ typedef struct _RTL_CRITICAL_SECTION GTEST_CRITICAL_SECTION;
669658

670659
// Typed tests need <typeinfo> and variadic macros, which GCC, VC++ 8.0,
671660
// Sun Pro CC, IBM Visual Age, and HP aCC support.
672-
#if defined(__GNUC__) || (_MSC_VER >= 1400) || defined(__SUNPRO_CC) || \
661+
#if defined(__GNUC__) || defined(_MSC_VER) || defined(__SUNPRO_CC) || \
673662
defined(__IBMCPP__) || defined(__HP_aCC)
674663
# define GTEST_HAS_TYPED_TEST 1
675664
# define GTEST_HAS_TYPED_TEST_P 1
@@ -2321,13 +2310,12 @@ GTEST_DISABLE_MSC_DEPRECATED_POP_()
23212310
// MSVC-based platforms. We map the GTEST_SNPRINTF_ macro to the appropriate
23222311
// function in order to achieve that. We use macro definition here because
23232312
// snprintf is a variadic function.
2324-
#if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
2313+
#if _MSC_VER && !GTEST_OS_WINDOWS_MOBILE
23252314
// MSVC 2005 and above support variadic macros.
23262315
# define GTEST_SNPRINTF_(buffer, size, format, ...) \
23272316
_snprintf_s(buffer, size, size, format, __VA_ARGS__)
23282317
#elif defined(_MSC_VER)
2329-
// Windows CE does not define _snprintf_s and MSVC prior to 2005 doesn't
2330-
// complain about _snprintf.
2318+
// Windows CE does not define _snprintf_s
23312319
# define GTEST_SNPRINTF_ _snprintf
23322320
#else
23332321
# define GTEST_SNPRINTF_ snprintf

googletest/src/gtest.cc

+3-16
Original file line numberDiff line numberDiff line change
@@ -4537,24 +4537,17 @@ void TestEventListeners::SuppressEventForwarding() {
45374537
// call this before main() starts, from which point on the return
45384538
// value will never change.
45394539
UnitTest* UnitTest::GetInstance() {
4540-
// When compiled with MSVC 7.1 in optimized mode, destroying the
4541-
// UnitTest object upon exiting the program messes up the exit code,
4542-
// causing successful tests to appear failed. We have to use a
4543-
// different implementation in this case to bypass the compiler bug.
4544-
// This implementation makes the compiler happy, at the cost of
4545-
// leaking the UnitTest object.
4546-
45474540
// CodeGear C++Builder insists on a public destructor for the
45484541
// default implementation. Use this implementation to keep good OO
45494542
// design with private destructor.
45504543

4551-
#if (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
4544+
#if defined(__BORLANDC__)
45524545
static UnitTest* const instance = new UnitTest;
45534546
return instance;
45544547
#else
45554548
static UnitTest instance;
45564549
return &instance;
4557-
#endif // (_MSC_VER == 1310 && !defined(_DEBUG)) || defined(__BORLANDC__)
4550+
#endif // defined(__BORLANDC__)
45584551
}
45594552

45604553
// Gets the number of successful test cases.
@@ -4812,18 +4805,12 @@ int UnitTest::Run() {
48124805
_set_error_mode(_OUT_TO_STDERR);
48134806
# endif
48144807

4815-
# if _MSC_VER >= 1400 && !GTEST_OS_WINDOWS_MOBILE
4808+
# if defined(_MSC_VER) && !GTEST_OS_WINDOWS_MOBILE
48164809
// In the debug version, Visual Studio pops up a separate dialog
48174810
// offering a choice to debug the aborted program. We need to suppress
48184811
// this dialog or it will pop up for every EXPECT/ASSERT_DEATH statement
48194812
// executed. Google Test will notify the user of any unexpected
48204813
// failure via stderr.
4821-
//
4822-
// VC++ doesn't define _set_abort_behavior() prior to the version 8.0.
4823-
// Users of prior VC versions shall suffer the agony and pain of
4824-
// clicking through the countless debug dialogs.
4825-
// FIXME: find a way to suppress the abort dialog() in the
4826-
// debug mode when compiled with VC 7.1 or lower.
48274814
if (!GTEST_FLAG(break_on_failure))
48284815
_set_abort_behavior(
48294816
0x0, // Clear the following flags:

googletest/test/gtest_unittest.cc

-3
Original file line numberDiff line numberDiff line change
@@ -7277,9 +7277,6 @@ TEST(IsHashTable, Basic) {
72777277
EXPECT_FALSE(testing::internal::IsHashTable<NotReallyAHashTable>::value);
72787278
EXPECT_FALSE(testing::internal::IsHashTable<std::vector<int>>::value);
72797279
EXPECT_TRUE(testing::internal::IsHashTable<std::unordered_set<int>>::value);
7280-
#if GTEST_HAS_HASH_SET_
7281-
EXPECT_TRUE(testing::internal::IsHashTable<__gnu_cxx::hash_set<int>>::value);
7282-
#endif // GTEST_HAS_HASH_SET_
72837280
}
72847281

72857282
// Tests ArrayEq().

0 commit comments

Comments
 (0)