From 0934b7e112354d609133d2c5f973c402c9efc9b9 Mon Sep 17 00:00:00 2001 From: Derek Mauro Date: Tue, 16 Sep 2025 10:38:37 -0700 Subject: [PATCH] Use an internal symbol for deprecate-and-inline that allows the use of a deprecation message PiperOrigin-RevId: 807753856 Change-Id: I34b0c7c6faf34cad11ea2aca5ccd16bca16acdec --- googlemock/include/gmock/gmock-actions.h | 8 ++++---- googlemock/include/gmock/internal/gmock-port.h | 13 ++----------- googletest/include/gtest/internal/gtest-port.h | 7 +++++++ 3 files changed, 13 insertions(+), 15 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 2746edd34..68d5cedad 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1868,7 +1868,7 @@ typedef internal::IgnoredValue Unused; // Deprecated single-argument DoAll. template -GMOCK_DEPRECATE_AND_INLINE() +GTEST_INTERNAL_DEPRECATE_AND_INLINE("Avoid using DoAll() for single actions") typename std::decay::type DoAll(Action&& action) { return std::forward(action); } @@ -2038,11 +2038,11 @@ PolymorphicAction> SetErrnoAndReturn( // Various overloads for Invoke(). // Legacy function. -// Actions can now be implicitly constructed from callables. No need to create -// wrapper objects. // This function exists for backwards compatibility. template -GMOCK_DEPRECATE_AND_INLINE() +GTEST_INTERNAL_DEPRECATE_AND_INLINE( + "Actions can now be implicitly constructed from callables. No need to " + "create wrapper objects using Invoke().") typename std::decay::type Invoke(FunctionImpl&& function_impl) { return std::forward(function_impl); } diff --git a/googlemock/include/gmock/internal/gmock-port.h b/googlemock/include/gmock/internal/gmock-port.h index c23b69df9..42d36d2f1 100644 --- a/googlemock/include/gmock/internal/gmock-port.h +++ b/googlemock/include/gmock/internal/gmock-port.h @@ -57,19 +57,10 @@ #include "gmock/internal/custom/gmock-port.h" #include "gtest/internal/gtest-port.h" -#if defined(GTEST_HAS_ABSL) -#include "absl/base/macros.h" - -#define GMOCK_DEPRECATE_AND_INLINE() ABSL_DEPRECATE_AND_INLINE() - -#if !defined(GTEST_NO_ABSL_FLAGS) +#if defined(GTEST_HAS_ABSL) && !defined(GTEST_NO_ABSL_FLAGS) #include "absl/flags/declare.h" #include "absl/flags/flag.h" -#endif // !defined(GTEST_NO_ABSL_FLAGS) - -#else // defined(GTEST_HAS_ABSL) -#define GMOCK_DEPRECATE_AND_INLINE() -#endif // defined(GTEST_HAS_ABSL) +#endif // For MS Visual C++, check the compiler version. At least VS 2015 is // required to compile Google Mock. diff --git a/googletest/include/gtest/internal/gtest-port.h b/googletest/include/gtest/internal/gtest-port.h index 9bd41cd62..f810d0644 100644 --- a/googletest/include/gtest/internal/gtest-port.h +++ b/googletest/include/gtest/internal/gtest-port.h @@ -2322,6 +2322,13 @@ const char* StringFromGTestEnv(const char* flag, const char* default_val); } // namespace internal } // namespace testing +#if GTEST_INTERNAL_HAVE_CPP_ATTRIBUTE(clang::annotate) +#define GTEST_INTERNAL_DEPRECATE_AND_INLINE(msg) \ + [[deprecated(msg), clang::annotate("inline-me")]] +#else +#define GTEST_INTERNAL_DEPRECATE_AND_INLINE(msg) [[deprecated(msg)]] +#endif + #if defined(__cpp_lib_span) || (GTEST_INTERNAL_HAS_INCLUDE() && \ GTEST_INTERNAL_CPLUSPLUS_LANG >= 202002L) #define GTEST_INTERNAL_HAS_STD_SPAN 1