Skip to content

Commit 2ce9d8f

Browse files
Abseil Teamcopybara-github
authored andcommitted
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
1 parent 279f847 commit 2ce9d8f

File tree

1 file changed

+15
-2
lines changed

1 file changed

+15
-2
lines changed

googlemock/include/gmock/gmock-actions.h

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1796,11 +1796,24 @@ struct SetArrayArgumentAction {
17961796
};
17971797

17981798
template <size_t k>
1799-
struct DeleteArgAction {
1799+
class DeleteArgAction {
1800+
public:
18001801
template <typename... Args>
18011802
void operator()(const Args&... args) const {
1802-
delete std::get<k>(std::tie(args...));
1803+
DoDelete(std::get<k>(std::tie(args...)));
18031804
}
1805+
1806+
private:
1807+
template <typename T>
1808+
static void DoDelete(T* ptr) {
1809+
delete ptr;
1810+
}
1811+
1812+
template <typename T>
1813+
[[deprecated(
1814+
"DeleteArg<N> used for a non-pointer argument, it was likely migrated "
1815+
"to a smart pointer type. This action should be removed.")]]
1816+
static void DoDelete(T&) {}
18041817
};
18051818

18061819
template <typename Ptr>

0 commit comments

Comments
 (0)