OSDN Git Service

libpdx: Fix bug in Variant type.
authorCorey Tabaka <eieio@google.com>
Thu, 1 Jun 2017 07:24:49 +0000 (00:24 -0700)
committerCorey Tabaka <eieio@google.com>
Fri, 2 Jun 2017 18:24:14 +0000 (11:24 -0700)
commitdfee6a7b9491fd9b5e4d570d9dbc0336fa2e9acb
tree75bc6fb3c11bc2aa1c80b720e13eda2c3ffbb867
parent5d5c530a8b9fa641547fdf68b4c577d73685011c
libpdx: Fix bug in Variant type.

Fix a subtle bug in the Variant value destruction along the
EmptyVariant assignment path:

    some_variant = EmptyVariant{};

The problem arises from the private utility method Destruct(),
which does not set the type index to "empty" after destroying the
current sub-element. For most paths this is okay because the type
index is immediately set to the new sub-element type. However, the
EmptyVariant path does not assign a new type because the Variant
should become empty. Since the type is not set to "empty" the
Variant incorrectly double destroys the previous value when a new
value is assigned.

Also clean up a superfluous overload of Assign() that is skipped
due to the stronger binding of the universal reference overload
Assign(T&&).

Update tests to properly cover this case. In the process discovered
two incorrect tests related to this issue and updated them.

Bug: None
Test: pdx_tests passes.
Change-Id: I106f863b34f2719820d04d0e701968332f659c3e
libs/vr/libpdx/private/pdx/rpc/variant.h
libs/vr/libpdx/variant_tests.cpp