From 44517f9888def81f75c1114a0a881bd716331132 Mon Sep 17 00:00:00 2001 From: Mark Jan van Kampen Date: Wed, 22 Jan 2020 22:29:28 +0100 Subject: [PATCH 1/8] Fixes extensions missing for QNX --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 755b8b72..4c8188aa 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -15,7 +15,7 @@ if (CMAKE_VERSION VERSION_LESS "3.1") else() set(CMAKE_CXX_STANDARD 11) set(CMAKE_CXX_STANDARD_REQUIRED ON) - 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() -- Gitee From a2533417cab3d38e71957d807468274a6605d20b Mon Sep 17 00:00:00 2001 From: Eli Lindsey Date: Sat, 30 May 2020 15:26:33 -0400 Subject: [PATCH 2/8] fix compilation on OpenBSD 6.7 Building on OpenBSD 6.7 current fails due to implicit numeric conversions: OpenBSD clang version 8.0.1 (tags/RELEASE_801/final) (based on LLVM 8.0.1) Target: amd64-unknown-openbsd6.7 Thread model: posix InstalledDir: /usr/bin In file included from /tmp/u/build/_deps/googletest-src/googletest/src/gtest-all.cc:45: /tmp/u/build/_deps/googletest-src/googletest/src/gtest-port.cc:201:19: error: implicit conversion changes signedness: 'int' to 'unsigned long' [-Werror,-Wsign-conversion] mib[5] = size / mib[4]; ~ ^~~~~~ /tmp/u/build/_deps/googletest-src/googletest/src/gtest-port.cc:211:33: error: implicit conversion changes signedness: 'int' to 'unsigned long' [-Werror,-Wsign-conversion] for (size_t i = 0; i < size / mib[4]; i++) { ~ ^~~~~~ /tmp/u/build/_deps/googletest-src/googletest/src/gtest-port.cc:215:10: error: implicit conversion changes signedness: 'int' to 'size_t' (aka 'unsigned long') [-Werror,-Wsign-conversion] return nthreads; ~~~~~~ ^~~~~~~~ /tmp/u/build/_deps/googletest-src/googletest/src/gtest-port.cc:201:17: error: implicit conversion loses integer precision: 'unsigned long' to 'int' [-Werror,-Wshorten-64-to-32] mib[5] = size / mib[4]; ~ ~~~~~^~~~~~~~ 4 errors generated. --- googletest/src/gtest-port.cc | 7 ++++--- 1 file changed, 4 insertions(+), 3 deletions(-) diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index c1802337..3f39f71c 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++; } -- Gitee From 131878ce9e18e3fcc5fdd690c93ee9d36f0a18d3 Mon Sep 17 00:00:00 2001 From: Olivier Ldff Date: Sat, 11 Apr 2020 16:44:37 +0200 Subject: [PATCH 3/8] use target_compile_features to use c++11 if cmake > 3.8 If target_compile_features is available and cxx_std_11. This fix compilation with clang and gcc when c++11 isn't specified by user. --- googletest/cmake/internal_utils.cmake | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 2f70f0b0..b3e8b819 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() ######################################################################## -- Gitee From 356f2d264a485db2fcc50ec1c672e0d37b6cb39b Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Wed, 1 Jul 2020 15:40:49 -0400 Subject: [PATCH 4/8] Googletest export Improve compatibility with strict compilers targeting Windows Remove an unnecessary ##, which could result in warnings about invalid preprocessor tokens when pasting to an initial '(' PiperOrigin-RevId: 319277617 --- googlemock/include/gmock/gmock-function-mocker.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/include/gmock/gmock-function-mocker.h b/googlemock/include/gmock/gmock-function-mocker.h index 317d6c2b..7140a289 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 -- Gitee From b9a8afcf2ee1a56f4617e253d95a10a4406f537f Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Jul 2020 11:51:37 -0400 Subject: [PATCH 5/8] Googletest export Fix mismatch between `int` and `int32_t` in the parse function. On some platforms, those are different types. PiperOrigin-RevId: 319991862 --- googlemock/src/gmock.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/googlemock/src/gmock.cc b/googlemock/src/gmock.cc index 32b2a739..7bcdb0ba 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); -- Gitee From 9aaaaf3f3d0099b4130660a1d4af6c6710482889 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Tue, 7 Jul 2020 11:57:38 -0400 Subject: [PATCH 6/8] Googletest export Cleanup: Error message grammar fix. PiperOrigin-RevId: 319992912 --- googlemock/src/gmock-spec-builders.cc | 2 +- googlemock/test/gmock_output_test_golden.txt | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/googlemock/src/gmock-spec-builders.cc b/googlemock/src/gmock-spec-builders.cc index 81ea9894..346e6809 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/test/gmock_output_test_golden.txt b/googlemock/test/gmock_output_test_golden.txt index 4c90b41a..755e9334 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. -- Gitee From 08b787796c5f18317feeb4063982a3fd3c650cfd Mon Sep 17 00:00:00 2001 From: ofats Date: Tue, 7 Jul 2020 12:47:27 -0400 Subject: [PATCH 7/8] Googletest export Replace ByRef with std::ref everywhere in docs. PiperOrigin-RevId: 320002303 --- googlemock/docs/cheat_sheet.md | 12 ++++++------ googlemock/docs/cook_book.md | 27 ++++++++++++--------------- 2 files changed, 18 insertions(+), 21 deletions(-) diff --git a/googlemock/docs/cheat_sheet.md b/googlemock/docs/cheat_sheet.md index a39c6e9f..85620f71 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 9550d912..3fc1198a 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: -- Gitee From 70b90929b1da20580cad9ed996397cf04ef8f16d Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Thu, 9 Jul 2020 00:44:49 -0400 Subject: [PATCH 8/8] Googletest export Adding std:: namespace to string in the example PiperOrigin-RevId: 320327910 --- googletest/docs/advanced.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/googletest/docs/advanced.md b/googletest/docs/advanced.md index 60c1a2b0..a3319384 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); }, '_'); -- Gitee