From 2ce9d8f2e85550a94d6ac977c881fe3658129ac6 Mon Sep 17 00:00:00 2001 From: Abseil Team Date: Mon, 13 Oct 2025 06:50:27 -0700 Subject: [PATCH] Allow for passing non-pointers to DeleteArg and have them emit a deprecation warning instead. This allows for simpler migration of function args to smart pointers without needing all changes to tests to be atomic. PiperOrigin-RevId: 818635600 Change-Id: I9434685d9640f82b98d0b5261701b78c93d3ec1e --- googlemock/include/gmock/gmock-actions.h | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/googlemock/include/gmock/gmock-actions.h b/googlemock/include/gmock/gmock-actions.h index 68d5cedad..fe3b41ca8 100644 --- a/googlemock/include/gmock/gmock-actions.h +++ b/googlemock/include/gmock/gmock-actions.h @@ -1796,11 +1796,24 @@ struct SetArrayArgumentAction { }; template -struct DeleteArgAction { +class DeleteArgAction { + public: template void operator()(const Args&... args) const { - delete std::get(std::tie(args...)); + DoDelete(std::get(std::tie(args...))); } + + private: + template + static void DoDelete(T* ptr) { + delete ptr; + } + + template + [[deprecated( + "DeleteArg used for a non-pointer argument, it was likely migrated " + "to a smart pointer type. This action should be removed.")]] + static void DoDelete(T&) {} }; template