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
This commit is contained in:
Abseil Team 2025-10-13 06:50:27 -07:00 committed by Copybara-Service
parent 279f847946
commit 2ce9d8f2e8

View File

@ -1796,11 +1796,24 @@ struct SetArrayArgumentAction {
}; };
template <size_t k> template <size_t k>
struct DeleteArgAction { class DeleteArgAction {
public:
template <typename... Args> template <typename... Args>
void operator()(const Args&... args) const { void operator()(const Args&... args) const {
delete std::get<k>(std::tie(args...)); DoDelete(std::get<k>(std::tie(args...)));
} }
private:
template <typename T>
static void DoDelete(T* ptr) {
delete ptr;
}
template <typename T>
[[deprecated(
"DeleteArg<N> 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 <typename Ptr> template <typename Ptr>