mirror of
https://gitlab.kitware.com/vtk/vtk-m
synced 2024-07-30 18:50:59 +00:00
Fix issue with Variant::CastAndCall with non-const reference
There was a typo in the declaration of the `CastAndCall` for a non-const `Variant`. When determining the `noexcept` status of the function being called, it was passing in a const reference instead of a regular reference, which is what is actually passed to the function. This potentially causes the function call to not match and fail to compile.
This commit is contained in:
parent
b44b30ddb2
commit
3ec9fc8580
@ -21,6 +21,7 @@ namespace test_variant
|
||||
template <vtkm::IdComponent Index>
|
||||
struct TypePlaceholder
|
||||
{
|
||||
vtkm::IdComponent Value = Index;
|
||||
};
|
||||
|
||||
// A class that is trivially copiable but not totally trivial.
|
||||
@ -313,6 +314,17 @@ struct TestFunctor
|
||||
}
|
||||
};
|
||||
|
||||
struct TestFunctorModify
|
||||
{
|
||||
template <vtkm::IdComponent Index>
|
||||
void operator()(TypePlaceholder<Index>& object, vtkm::Id expectedValue)
|
||||
{
|
||||
VTKM_TEST_ASSERT(Index == expectedValue, "Index = ", Index, ", expected = ", expectedValue);
|
||||
VTKM_TEST_ASSERT(object.Value == expectedValue);
|
||||
++object.Value;
|
||||
}
|
||||
};
|
||||
|
||||
void TestGet()
|
||||
{
|
||||
std::cout << "Test Get" << std::endl;
|
||||
@ -429,6 +441,9 @@ void TestCastAndCall()
|
||||
VariantType variant26{ TypePlaceholder<26>{} };
|
||||
result = variant26.CastAndCall(TestFunctor(), 26);
|
||||
VTKM_TEST_ASSERT(test_equal(result, TestValue(26, vtkm::FloatDefault{})));
|
||||
|
||||
variant1.CastAndCall(TestFunctorModify{}, 1);
|
||||
VTKM_TEST_ASSERT(variant1.Get<1>().Value == 2, "Variant object not updated.");
|
||||
}
|
||||
|
||||
void TestCopyInvalid()
|
||||
|
@ -518,8 +518,9 @@ public:
|
||||
}
|
||||
|
||||
template <typename Functor, typename... Args>
|
||||
VTK_M_DEVICE auto CastAndCall(Functor&& f, Args&&... args) noexcept(
|
||||
noexcept(f(std::declval<const TypeAt<0>&>(), args...)))
|
||||
VTK_M_DEVICE auto CastAndCall(Functor&& f,
|
||||
Args&&... args) noexcept(noexcept(f(std::declval<TypeAt<0>&>(),
|
||||
args...)))
|
||||
-> decltype(f(std::declval<TypeAt<0>&>(), args...))
|
||||
{
|
||||
VTKM_ASSERT(this->IsValid());
|
||||
|
Loading…
Reference in New Issue
Block a user