From a96e956c30d811a13c7e2226863b290e0edf0ed3 Mon Sep 17 00:00:00 2001 From: Victor Zverovich Date: Fri, 28 Feb 2025 20:26:07 -0800 Subject: [PATCH] Make the intent clearer in manage_as_static Summary: Add a comment clarifying why we use a ctor that alliases an empty `shared_ptr` in `manage_as_static`. Without a comment it's a bit hard to figure out the behavior we get from the docs in https://en.cppreference.com/w/cpp/memory/shared_ptr/shared_ptr, esp. since the set of relevant overloads changed in C++20. Reviewed By: praihan Differential Revision: D70422993 fbshipit-source-id: de642aa1f4d7ba73c82821923a052b666c54b3f6 --- third-party/thrift/src/thrift/compiler/whisker/managed_ptr.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/third-party/thrift/src/thrift/compiler/whisker/managed_ptr.h b/third-party/thrift/src/thrift/compiler/whisker/managed_ptr.h index f2752c64e819b2..db3bc37cda94bc 100644 --- a/third-party/thrift/src/thrift/compiler/whisker/managed_ptr.h +++ b/third-party/thrift/src/thrift/compiler/whisker/managed_ptr.h @@ -44,6 +44,8 @@ using managed_ptr = std::shared_ptr; */ template managed_ptr manage_as_static(const T& o) { + // Alias an empty shared_ptr to create a non-owning shared_ptr that doesn't + // allocate a control block (unlike using a noop deleter). return managed_ptr(managed_ptr(), std::addressof(o)); }