Merge pull request #5033 from UditDewan:fix/absolute-install-includedir PiperOrigin-RevId: 953333932 Change-Id: I1f3dfb118bb2a7e3b4ae64fcc4206baf4c8e7f4b
diff --git a/googlemock/test/gmock-actions_test.cc b/googlemock/test/gmock-actions_test.cc index 0a03349..f0218b7 100644 --- a/googlemock/test/gmock-actions_test.cc +++ b/googlemock/test/gmock-actions_test.cc
@@ -1222,23 +1222,26 @@ // Tests InvokeWithoutArgs(function). TEST(InvokeWithoutArgsTest, Function) { + GTEST_DISABLE_DEPRECATED_PUSH_() // As an action that takes one argument. - Action<int(int)> a = Nullary; // NOLINT + Action<int(int)> a = InvokeWithoutArgs(Nullary); // NOLINT EXPECT_EQ(1, a.Perform(std::make_tuple(2))); // As an action that takes two arguments. - Action<int(int, double)> a2 = Nullary; // NOLINT + Action<int(int, double)> a2 = InvokeWithoutArgs(Nullary); // NOLINT EXPECT_EQ(1, a2.Perform(std::make_tuple(2, 3.5))); // As an action that returns void. - Action<void(int)> a3 = VoidNullary; // NOLINT + Action<void(int)> a3 = InvokeWithoutArgs(VoidNullary); // NOLINT g_done = false; a3.Perform(std::make_tuple(1)); EXPECT_TRUE(g_done); + GTEST_DISABLE_DEPRECATED_POP_() } // Tests InvokeWithoutArgs(functor). TEST(InvokeWithoutArgsTest, Functor) { + GTEST_DISABLE_DEPRECATED_PUSH_() // As an action that takes no argument. Action<int()> a = InvokeWithoutArgs(NullaryFunctor()); // NOLINT EXPECT_EQ(2, a.Perform(std::make_tuple())); @@ -1253,6 +1256,7 @@ g_done = false; a3.Perform(std::make_tuple()); EXPECT_TRUE(g_done); + GTEST_DISABLE_DEPRECATED_POP_() } // Tests InvokeWithoutArgs(obj_ptr, method).
diff --git a/googlemock/test/gmock_link_test.h b/googlemock/test/gmock_link_test.h index 41bfba0..6f749bb 100644 --- a/googlemock/test/gmock_link_test.h +++ b/googlemock/test/gmock_link_test.h
@@ -338,10 +338,12 @@ Mock mock; InvokeHelper test_invoke_helper; + GTEST_DISABLE_DEPRECATED_PUSH_() EXPECT_CALL(mock, VoidFromString(_)) .WillOnce(InvokeWithoutArgs(&InvokeHelper::StaticVoidFromVoid)) .WillOnce( InvokeWithoutArgs(&test_invoke_helper, &InvokeHelper::VoidFromVoid)); + GTEST_DISABLE_DEPRECATED_POP_() mock.VoidFromString(nullptr); mock.VoidFromString(nullptr); }
diff --git a/googletest/cmake/internal_utils.cmake b/googletest/cmake/internal_utils.cmake index 5429c9d..e7f33ff 100644 --- a/googletest/cmake/internal_utils.cmake +++ b/googletest/cmake/internal_utils.cmake
@@ -35,21 +35,21 @@ # preferable to use CRT as static libraries, as we don't have to rely # on CRT DLLs being available. CMake always defaults to using shared # CRT libraries, so we override that default here. - string(REPLACE "/MD" "-MT" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])MD" "\\1MT" ${flag_var} "${${flag_var}}") # When using Ninja with Clang, static builds pass -D_DLL on Windows. # This is incorrect and should not happen, so we fix that here. - string(REPLACE "-D_DLL" "" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])D_DLL" "" ${flag_var} "${${flag_var}}") endif() # We prefer more strict warning checking for building Google Test. # Replaces /W3 with /W4 in defaults. - string(REPLACE "/W3" "/W4" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])W3" "\\1W4" ${flag_var} "${${flag_var}}") # Prevent D9025 warning for targets that have exception handling # turned off (/EHs-c- flag). Where required, exceptions are explicitly # re-enabled using the cxx_exception_flags variable. - string(REPLACE "/EHsc" "" ${flag_var} "${${flag_var}}") + string(REGEX REPLACE "([/-])EHsc" "" ${flag_var} "${${flag_var}}") endforeach() endif() endmacro() @@ -63,6 +63,7 @@ unset(GTEST_HAS_PTHREAD) if (NOT gtest_disable_pthreads AND NOT MINGW) # Defines CMAKE_USE_PTHREADS_INIT and CMAKE_THREAD_LIBS_INIT. + set(THREADS_PREFER_PTHREAD_FLAG TRUE) find_package(Threads) if (CMAKE_USE_PTHREADS_INIT) set(GTEST_HAS_PTHREAD ON)
diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 8b32dae..31654b0 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h
@@ -363,18 +363,24 @@ #define GTEST_DISABLE_MSC_WARNINGS_POP_() #endif -// Clang on Windows does not understand MSVC's pragma warning. -// We need clang-specific way to disable function deprecation warning. -#ifdef __clang__ -#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ +// Pragmas to disable function deprecation warnings. +#if defined(__clang__) +#define GTEST_DISABLE_DEPRECATED_PUSH_() \ _Pragma("clang diagnostic push") \ _Pragma("clang diagnostic ignored \"-Wdeprecated-declarations\"") \ _Pragma("clang diagnostic ignored \"-Wdeprecated-implementations\"") -#define GTEST_DISABLE_MSC_DEPRECATED_POP_() _Pragma("clang diagnostic pop") +#define GTEST_DISABLE_DEPRECATED_POP_() _Pragma("clang diagnostic pop") +#elif defined(__GNUC__) +#define GTEST_DISABLE_DEPRECATED_PUSH_() \ + _Pragma("GCC diagnostic push") \ + _Pragma("GCC diagnostic ignored \"-Wdeprecated-declarations\"") +#define GTEST_DISABLE_DEPRECATED_POP_() _Pragma("GCC diagnostic pop") +#elif defined(_MSC_VER) +#define GTEST_DISABLE_DEPRECATED_PUSH_() GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) +#define GTEST_DISABLE_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() #else -#define GTEST_DISABLE_MSC_DEPRECATED_PUSH_() \ - GTEST_DISABLE_MSC_WARNINGS_PUSH_(4996) -#define GTEST_DISABLE_MSC_DEPRECATED_POP_() GTEST_DISABLE_MSC_WARNINGS_POP_() +#define GTEST_DISABLE_DEPRECATED_PUSH_() +#define GTEST_DISABLE_DEPRECATED_POP_() #endif // Brings in definitions for functions used in the testing::internal::posix @@ -2119,7 +2125,7 @@ // Functions deprecated by MSVC 8.0. -GTEST_DISABLE_MSC_DEPRECATED_PUSH_() +GTEST_DISABLE_DEPRECATED_PUSH_() // ChDir(), FReopen(), FDOpen(), Read(), Write(), Close(), and // StrError() aren't needed on Windows CE at this time and thus not @@ -2181,7 +2187,7 @@ #endif } -GTEST_DISABLE_MSC_DEPRECATED_POP_() +GTEST_DISABLE_DEPRECATED_POP_() #ifdef GTEST_OS_WINDOWS_MOBILE // Windows CE has no C library. The abort() function is used in @@ -2302,22 +2308,29 @@ // Macros for defining flags. #define GTEST_DEFINE_bool_(name, default_val, doc) \ + GTEST_DECLARE_bool_(name); \ namespace testing { \ GTEST_API_ bool GTEST_FLAG(name) = (default_val); \ } \ static_assert(true, "no-op to require trailing semicolon") #define GTEST_DEFINE_int32_(name, default_val, doc) \ + GTEST_DECLARE_int32_(name); \ namespace testing { \ GTEST_API_ std::int32_t GTEST_FLAG(name) = (default_val); \ } \ static_assert(true, "no-op to require trailing semicolon") #define GTEST_DEFINE_string_(name, default_val, doc) \ + GTEST_DECLARE_string_(name); \ namespace testing { \ GTEST_API_ ::std::string GTEST_FLAG(name) = (default_val); \ } \ static_assert(true, "no-op to require trailing semicolon") // Macros for declaring flags. +// +// We also need to declare the flag in the public namespace to avoid triggering +// -Wmissing-variable-declarations warnings, as reported here: +// https://github.com/google/googletest/issues/4897 #define GTEST_DECLARE_bool_(name) \ namespace testing { \ GTEST_API_ extern bool GTEST_FLAG(name); \
diff --git a/googletest/src/gtest-port.cc b/googletest/src/gtest-port.cc index d34a693..4f4f2d8 100644 --- a/googletest/src/gtest-port.cc +++ b/googletest/src/gtest-port.cc
@@ -1069,7 +1069,7 @@ // Disable Microsoft deprecation warnings for POSIX functions called from // this class (creat, dup, dup2, and close) -GTEST_DISABLE_MSC_DEPRECATED_PUSH_() +GTEST_DISABLE_DEPRECATED_PUSH_() namespace { @@ -1200,7 +1200,7 @@ CapturedStream& operator=(const CapturedStream&) = delete; }; -GTEST_DISABLE_MSC_DEPRECATED_POP_() +GTEST_DISABLE_DEPRECATED_POP_() static CapturedStream* g_captured_stderr = nullptr; static CapturedStream* g_captured_stdout = nullptr;
diff --git a/googletest/src/gtest.cc b/googletest/src/gtest.cc index b38f551..92ea581 100644 --- a/googletest/src/gtest.cc +++ b/googletest/src/gtest.cc
@@ -5172,9 +5172,12 @@ // create the file with a single "0" character in it. I/O // errors are ignored as there's nothing better we can do and we // don't want to fail the test because of this. - FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w"); - fwrite("0", 1, 1, pfile); - fclose(pfile); + if (FILE* pfile = posix::FOpen(premature_exit_filepath_.c_str(), "w")) { + fwrite("0", 1, 1, pfile); + fclose(pfile); + } else { + premature_exit_filepath_.clear(); + } } } @@ -5192,7 +5195,7 @@ } private: - const std::string premature_exit_filepath_; + std::string premature_exit_filepath_; ScopedPrematureExitFile(const ScopedPrematureExitFile&) = delete; ScopedPrematureExitFile& operator=(const ScopedPrematureExitFile&) = delete;
diff --git a/googletest/test/gtest_unittest.cc b/googletest/test/gtest_unittest.cc index 8ce64d3..c753c36 100644 --- a/googletest/test/gtest_unittest.cc +++ b/googletest/test/gtest_unittest.cc
@@ -442,11 +442,11 @@ void SetUp() override { saved_tz_.reset(); - GTEST_DISABLE_MSC_DEPRECATED_PUSH_(/* getenv: deprecated */) + GTEST_DISABLE_DEPRECATED_PUSH_(/* getenv: deprecated */) if (const char* tz = getenv("TZ")) { saved_tz_ = std::make_unique<std::string>(tz); } - GTEST_DISABLE_MSC_DEPRECATED_POP_() + GTEST_DISABLE_DEPRECATED_POP_() // Set the local time zone for FormatEpochTimeInMillisAsIso8601 to be // a fixed time zone for reproducibility purposes.