From 652f0e7b2a6db3e11f78b720f08dcb66751ec66a Mon Sep 17 00:00:00 2001 From: Jordan DeLong Date: Thu, 27 Jun 2013 22:13:29 -0700 Subject: [PATCH] Remove Variant::swap (unused) because TypedValue::operator= is scary TypedValue::operator= is potentially dangerous when you don't know where the TypedValue is actually living. The reason is it copies the m_aux from the rhs over the m_aux on the lhs, so if your TypedValue happens to live inside an HphpArray you can apparently break HphpArray invariants. Since we still often cast TypedValues to Variants when they live in HphpArrays, using TypedValue::operator= inside of Variant needs to be forbidden. It also is dubious (probably wrong) in any tv_helpers functions that mutate externally-owned TypedValues. This particular function turns out to be dead code anyway. --- hphp/runtime/base/type_variant.h | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/hphp/runtime/base/type_variant.h b/hphp/runtime/base/type_variant.h index 5b40023fc..5b54ade2d 100644 --- a/hphp/runtime/base/type_variant.h +++ b/hphp/runtime/base/type_variant.h @@ -516,18 +516,6 @@ class Variant : private TypedValue { return m_type == KindOfRef ? m_data.pref->var()->m_data.dbl : m_data.dbl; } - /** - * Can just swap the data between variants sometimes to avoid inc and decref - */ - void swap(Variant &other) { - static_assert(sizeof(Variant) == sizeof(TypedValue), "Reimplement this"); - auto& lhs = reinterpret_cast(*this); - auto& rhs = reinterpret_cast(other); - auto val = lhs; - lhs = rhs; - rhs = val; - } - /** * Operators */