diff --git a/thrift/lib/cpp2/op/detail/StructPatch.h b/thrift/lib/cpp2/op/detail/StructPatch.h index e30421fa0bc..f32ad967b9d 100644 --- a/thrift/lib/cpp2/op/detail/StructPatch.h +++ b/thrift/lib/cpp2/op/detail/StructPatch.h @@ -367,6 +367,24 @@ class StructPatch : public BaseEnsurePatch> { } } + ~StructPatch() { + if (false) { + // Implement this check in destructor to make sure it's instantiated. + op::for_each_ordinal([](auto id) { + static_assert( + !apache::thrift::detail::is_shared_or_unique_ptr_v< + op::get_field_ref>, + "Patching cpp.ref field is unsupported since we cannot distinguish " + "unqualified and optional fields. Why? The type of `foo.field()` " + "is `std::unique_ptr` regardless Whether field is optional or " + "unqualified. In addition, Thrift Patch has different behavior " + "between optional and unqualified fields, e.g. `PatchOp::Clear` " + "will clear an optional field, but set an unqualified field to the " + "intrinsic default."); + }); + } + } + private: using Base::data_; };