mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-09-19 02:25:42 +00:00
Merge topic 'copy-invalid-variant'
5e476d703 Enable copying invalid variants Acked-by: Kitware Robot <kwrobot@kitware.com> Acked-by: Li-Ta Lo <ollie@lanl.gov> Merge-request: !2794
This commit is contained in:
commit
5488a08987
5
docs/changelog/copy-invalid-variant.md
Normal file
5
docs/changelog/copy-invalid-variant.md
Normal file
@ -0,0 +1,5 @@
|
||||
# Fix bug with copying invalid variants
|
||||
|
||||
There was a bug where if you attempted to copy a `Variant` that was not
|
||||
valid (i.e. did not hold an object); a seg fault could happen. This has
|
||||
been changed to set the target variant to also be invalid.
|
@ -431,6 +431,23 @@ void TestCastAndCall()
|
||||
VTKM_TEST_ASSERT(test_equal(result, TestValue(26, vtkm::FloatDefault{})));
|
||||
}
|
||||
|
||||
void TestCopyInvalid()
|
||||
{
|
||||
std::cout << "Test copy invalid variant" << std::endl;
|
||||
|
||||
using VariantType = vtkm::exec::internal::Variant<TypePlaceholder<0>, NonTrivial>;
|
||||
|
||||
VariantType source;
|
||||
source.Reset();
|
||||
|
||||
VariantType destination1(source);
|
||||
VTKM_TEST_ASSERT(!destination1.IsValid());
|
||||
|
||||
VariantType destination2(TypePlaceholder<0>{});
|
||||
destination2 = source;
|
||||
VTKM_TEST_ASSERT(!destination2.IsValid());
|
||||
}
|
||||
|
||||
struct CountConstructDestruct
|
||||
{
|
||||
vtkm::Id* Count;
|
||||
@ -577,6 +594,7 @@ void RunTest()
|
||||
TestTriviallyCopyable();
|
||||
TestGet();
|
||||
TestCastAndCall();
|
||||
TestCopyInvalid();
|
||||
TestCopyDestroy();
|
||||
TestEmplace();
|
||||
TestConstructDestruct();
|
||||
|
@ -255,12 +255,17 @@ struct VariantConstructorImpl<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>,
|
||||
|
||||
VTK_M_DEVICE VariantConstructorImpl(const VariantConstructorImpl& src) noexcept
|
||||
: VariantStorageImpl<Ts...>(vtkm::internal::NullType{})
|
||||
{
|
||||
if (src.IsValid())
|
||||
{
|
||||
src.CastAndCall(VariantCopyConstructFunctor{}, this->Storage);
|
||||
}
|
||||
this->Index = src.Index;
|
||||
}
|
||||
|
||||
VTK_M_DEVICE VariantConstructorImpl& operator=(const VariantConstructorImpl& src) noexcept
|
||||
{
|
||||
if (src.IsValid())
|
||||
{
|
||||
if (this->GetIndex() == src.GetIndex())
|
||||
{
|
||||
@ -272,6 +277,11 @@ struct VariantConstructorImpl<vtkm::VTK_M_NAMESPACE::internal::Variant<Ts...>,
|
||||
src.CastAndCall(detail::VariantCopyConstructFunctor{}, this->Storage);
|
||||
this->Index = src.Index;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
this->Reset();
|
||||
}
|
||||
return *this;
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user