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:
Kenneth Moreland 2022-07-25 10:07:22 -06:00
parent b44b30ddb2
commit 3ec9fc8580
2 changed files with 18 additions and 2 deletions

@ -21,6 +21,7 @@ namespace test_variant
template <vtkm::IdComponent Index> template <vtkm::IdComponent Index>
struct TypePlaceholder struct TypePlaceholder
{ {
vtkm::IdComponent Value = Index;
}; };
// A class that is trivially copiable but not totally trivial. // 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() void TestGet()
{ {
std::cout << "Test Get" << std::endl; std::cout << "Test Get" << std::endl;
@ -429,6 +441,9 @@ void TestCastAndCall()
VariantType variant26{ TypePlaceholder<26>{} }; VariantType variant26{ TypePlaceholder<26>{} };
result = variant26.CastAndCall(TestFunctor(), 26); result = variant26.CastAndCall(TestFunctor(), 26);
VTKM_TEST_ASSERT(test_equal(result, TestValue(26, vtkm::FloatDefault{}))); 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() void TestCopyInvalid()

@ -518,8 +518,9 @@ public:
} }
template <typename Functor, typename... Args> template <typename Functor, typename... Args>
VTK_M_DEVICE auto CastAndCall(Functor&& f, Args&&... args) noexcept( VTK_M_DEVICE auto CastAndCall(Functor&& f,
noexcept(f(std::declval<const TypeAt<0>&>(), args...))) Args&&... args) noexcept(noexcept(f(std::declval<TypeAt<0>&>(),
args...)))
-> decltype(f(std::declval<TypeAt<0>&>(), args...)) -> decltype(f(std::declval<TypeAt<0>&>(), args...))
{ {
VTKM_ASSERT(this->IsValid()); VTKM_ASSERT(this->IsValid());