diff --git a/CMakeLists.txt b/CMakeLists.txt index 37e7b61211f97f8a6c1d35f494f8a0910e4a33eb..e516b4b7a6584f41da9c3202631ee04f63574607 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -11,7 +11,7 @@ project(googletest-distribution) set(GOOGLETEST_VERSION 1.10.0) if (CMAKE_VERSION VERSION_GREATER "3.0.2") - if(NOT CYGWIN AND NOT MSYS) + if(NOT CYGWIN AND NOT MSYS AND NOT ${CMAKE_SYSTEM_NAME} STREQUAL QNX) set(CMAKE_CXX_EXTENSIONS OFF) endif() endif() diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md index a39c6e9f94a10d19605988b74ba5c6d88134289a..85620f71bc4fc5a200ef22b88378d3b96598e617 100644 --- a/googlemock/docs/cheat_sheet.md +++ b/googlemock/docs/cheat_sheet.md @@ -279,9 +279,10 @@ Matcher | Description Except `Ref()`, these matchers make a *copy* of `value` in case it's modified or destructed later. If the compiler complains that `value` doesn't have a public -copy constructor, try wrap it in `ByRef()`, e.g. -`Eq(ByRef(non_copyable_value))`. If you do that, make sure `non_copyable_value` -is not changed afterwards, or the meaning of your matcher will be changed. +copy constructor, try wrap it in `std::ref()`, e.g. +`Eq(std::ref(non_copyable_value))`. If you do that, make sure +`non_copyable_value` is not changed afterwards, or the meaning of your matcher +will be changed. `IsTrue` and `IsFalse` are useful when you need to use a matcher, or for types that can be explicitly converted to Boolean, but are not implicitly converted to @@ -586,13 +587,12 @@ callback type instead of a derived one, e.g. ``` In `InvokeArgument(...)`, if an argument needs to be passed by reference, -wrap it inside `ByRef()`. For example, +wrap it inside `std::ref()`. For example, ```cpp -using ::testing::ByRef; using ::testing::InvokeArgument; ... -InvokeArgument<2>(5, string("Hi"), ByRef(foo)) +InvokeArgument<2>(5, string("Hi"), std::ref(foo)) ``` calls the mock function's #2 argument, passing to it `5` and `string("Hi")` by diff --git a/googlemock/docs/cook_book.md b/googlemock/docs/cook_book.md index 9550d91223af0f382f3373781043faefe567b8d6..3fc1198ac830926f90d8f3289ad498bd1e2cad35 100644 --- a/googlemock/docs/cook_book.md +++ b/googlemock/docs/cook_book.md @@ -1180,15 +1180,14 @@ executed. Just tell gMock that it should save a reference to `bar`, instead of a copy of it. Here's how: ```cpp -using ::testing::ByRef; using ::testing::Eq; using ::testing::Lt; ... // Expects that Foo()'s argument == bar. - EXPECT_CALL(mock_obj, Foo(Eq(ByRef(bar)))); + EXPECT_CALL(mock_obj, Foo(Eq(std::ref(bar)))); // Expects that Foo()'s argument < bar. - EXPECT_CALL(mock_obj, Foo(Lt(ByRef(bar)))); + EXPECT_CALL(mock_obj, Foo(Lt(std::ref(bar)))); ``` Remember: if you do this, don't change `bar` after the `EXPECT_CALL()`, or the @@ -1851,10 +1850,9 @@ Methods"). However, gMock doesn't let you use `ReturnRef()` in a mock function whose return type is not a reference, as doing that usually indicates a user error. So, what shall you do? -Though you may be tempted, DO NOT use `ByRef()`: +Though you may be tempted, DO NOT use `std::ref()`: ```cpp -using testing::ByRef; using testing::Return; class MockFoo : public Foo { @@ -1865,7 +1863,7 @@ class MockFoo : public Foo { int x = 0; MockFoo foo; EXPECT_CALL(foo, GetValue()) - .WillRepeatedly(Return(ByRef(x))); // Wrong! + .WillRepeatedly(Return(std::ref(x))); // Wrong! x = 42; EXPECT_EQ(42, foo.GetValue()); ``` @@ -1881,9 +1879,9 @@ Expected: 42 The reason is that `Return(*value*)` converts `value` to the actual return type of the mock function at the time when the action is *created*, not when it is *executed*. (This behavior was chosen for the action to be safe when `value` is -a proxy object that references some temporary objects.) As a result, `ByRef(x)` -is converted to an `int` value (instead of a `const int&`) when the expectation -is set, and `Return(ByRef(x))` will always return 0. +a proxy object that references some temporary objects.) As a result, +`std::ref(x)` is converted to an `int` value (instead of a `const int&`) when +the expectation is set, and `Return(std::ref(x))` will always return 0. `ReturnPointee(pointer)` was provided to solve this problem specifically. It returns the value pointed to by `pointer` at the time the action is *executed*: @@ -2376,7 +2374,7 @@ using ::testing::InvokeArgument; ``` What if the callable takes an argument by reference? No problem - just wrap it -inside `ByRef()`: +inside `std::ref()`: ```cpp ... @@ -2385,20 +2383,19 @@ inside `ByRef()`: (override)); ... using ::testing::_; - using ::testing::ByRef; using ::testing::InvokeArgument; ... MockFoo foo; Helper helper; ... EXPECT_CALL(foo, Bar(_)) - .WillOnce(InvokeArgument<0>(5, ByRef(helper))); - // ByRef(helper) guarantees that a reference to helper, not a copy of it, - // will be passed to the callback. + .WillOnce(InvokeArgument<0>(5, std::ref(helper))); + // std::ref(helper) guarantees that a reference to helper, not a copy of + // it, will be passed to the callback. ``` What if the callable takes an argument by reference and we do **not** wrap the -argument in `ByRef()`? Then `InvokeArgument()` will *make a copy* of the +argument in `std::ref()`? Then `InvokeArgument()` will *make a copy* of the argument, and pass a *reference to the copy*, instead of a reference to the original value, to the callable. This is especially handy when the argument is a temporary value: diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index 317d6c2b7eb8ce7eecc52437d213120c114821c6..7140a2894780f32116f3b1fdac5e2b0068873e2c 100644 --- a/googlemock/include/gmock/gmock-function-mocker.h +++ b/googlemock/include/gmock/gmock-function-mocker.h @@ -234,7 +234,7 @@ using internal::FunctionMocker; GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I( \ GMOCK_PP_CAT(GMOCK_INTERNAL_IS_CALLTYPE_HELPER_, _arg)) #define GMOCK_INTERNAL_GET_VALUE_CALLTYPE_I(_arg) \ - GMOCK_PP_CAT(GMOCK_PP_IDENTITY, _arg) + GMOCK_PP_IDENTITY _arg #define GMOCK_INTERNAL_IS_CALLTYPE_HELPER_Calltype diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 81ea98949c233083f81650f2923f41c7137148e5..346e6809850ffb80c10b600c6c403f6d6f47d245 100644 --- a/googlemock/src/gmock-spec-builders.cc +++ b/googlemock/src/gmock-spec-builders.cc @@ -624,7 +624,7 @@ class MockObjectRegistry { if (leaked_count > 0) { std::cout << "\nERROR: " << leaked_count << " leaked mock " << (leaked_count == 1 ? "object" : "objects") - << " found at program exit. Expectations on a mock object is " + << " found at program exit. Expectations on a mock object are " "verified when the object is destructed. Leaking a mock " "means that its expectations aren't verified, which is " "usually a test bug. If you really intend to leak a mock, " diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc index 32b2a7394fd08cb19c13d0017539bce308195db0..7bcdb0ba2dfca27676a81dda7791ace699516e31 100644 --- a/googlemock/src/gmock.cc +++ b/googlemock/src/gmock.cc @@ -124,7 +124,7 @@ static bool ParseGoogleMockStringFlag(const char* str, const char* flag, } static bool ParseGoogleMockIntFlag(const char* str, const char* flag, - int* value) { + int32_t* value) { // Gets the value of the flag as a string. const char* const value_str = ParseGoogleMockFlagValue(str, flag, true); diff --git a/googlemock/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index 4c90b41a3abc0b3fad262652b7faf25c7856bba3..755e9334a792596caaea79b67c3d63cf928d5119 100644 --- a/googlemock/test/gmock_output_test_golden.txt +++ b/googlemock/test/gmock_output_test_golden.txt @@ -314,4 +314,4 @@ Expected: is pair (is >= 48, true) FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. FILE:#: ERROR: this mock object should be deleted but never is. Its address is @0x#. -ERROR: 3 leaked mock objects found at program exit. Expectations on a mock object is verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock. +ERROR: 3 leaked mock objects found at program exit. Expectations on a mock object are verified when the object is destructed. Leaking a mock means that its expectations aren't verified, which is usually a test bug. If you really intend to leak a mock, you can suppress this error using testing::Mock::AllowLeak(mock_object), or you may use a fake or stub instead of a mock. diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 2f70f0b084b99e3a231e3d01593c0dee9c7228b6..b3e8b8190ea01fc89e6a7375c798b6ac58b2df95 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake @@ -188,6 +188,10 @@ function(cxx_library_with_type name type cxx_flags) endif() target_link_libraries(${name} PUBLIC ${threads_spec}) endif() + + if (NOT "${CMAKE_VERSION}" VERSION_LESS "3.8") + target_compile_features(${name} PUBLIC cxx_std_11) + endif() endfunction() ######################################################################## diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index 60c1a2b0b518b198be49203e7795e28203694a87..a3319384510cb1608f2573aa8b0a441bac6f97b8 100644 --- a/googletest/docs/advanced.md +++ b/googletest/docs/advanced.md @@ -1490,7 +1490,7 @@ for conciseness: ```c++ enum class MyType { MY_FOO = 0, MY_BAR = 1 }; -class MyTestSuite : public testing::TestWithParam> { +class MyTestSuite : public testing::TestWithParam> { }; INSTANTIATE_TEST_SUITE_P( @@ -1499,7 +1499,7 @@ INSTANTIATE_TEST_SUITE_P( testing::Values(MyType::VALUE_0, MyType::VALUE_1), testing::ValuesIn("", "")), [](const testing::TestParamInfo& info) { - string name = absl::StrCat( + std::string name = absl::StrCat( std::get<0>(info.param) == MY_FOO ? "Foo" : "Bar", "_", std::get<1>(info.param)); absl::c_replace_if(name, [](char c) { return !std::isalnum(c); }, '_'); diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index c180233735b750b8de643d9bf5e95f5ac00f5ef0..3f39f71c07459b5c011057771134e5c2b98ce9ff 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc @@ -198,7 +198,8 @@ size_t GetThreadCount() { if (sysctl(mib, miblen, NULL, &size, NULL, 0)) { return 0; } - mib[5] = size / mib[4]; + + mib[5] = static_cast(size / static_cast(mib[4])); // populate array of structs struct kinfo_proc info[mib[5]]; @@ -207,8 +208,8 @@ size_t GetThreadCount() { } // exclude empty members - int nthreads = 0; - for (size_t i = 0; i < size / mib[4]; i++) { + size_t nthreads = 0; + for (size_t i = 0; i < size / static_cast(mib[4]); i++) { if (info[i].p_tid != -1) nthreads++; }