Commit 878a5e5a authored by Kenneth Moreland's avatar Kenneth Moreland
Browse files

Disallow references in Variant

I have run into strange problems with reference types sneaking into
templates. Reference types can cause weird errors when passing things
across hosts and devices, and it's best not to let them sneak into an
object like Varient where they become more difficult to check for.
parent 8e70a7c5
......@@ -55,6 +55,19 @@ struct VariantDestroyFunctor
}
};
template <typename T>
struct VariantCheckType
{
// We are currently not allowing reference types (e.g. FooType&) or pointer types (e.g. FooType*)
// in Variant objects. References and pointers can fail badly when things are passed around
// devices. If you get a compiler error here, consider removing the reference or using something
// like std::decay to remove qualifiers on the type. (We may decide to do that automatically in
// the future.)
VTKM_STATIC_ASSERT_MSG(!std::is_reference<T>::value,
"References are not allowed in VTK-m Variant.");
VTKM_STATIC_ASSERT_MSG(!std::is_pointer<T>::value, "Pointers are not allowed in VTK-m Variant.");
};
template <typename... Ts>
struct AllTriviallyCopyable;
......@@ -306,6 +319,9 @@ class Variant : detail::VariantConstructorImpl<Variant<Ts...>>
{
using Superclass = detail::VariantConstructorImpl<Variant<Ts...>>;
// Type not used, but has the compiler check all the types for validity.
using CheckTypes = vtkm::List<detail::VariantCheckType<Ts>...>;
public:
/// Returns the index of the type of object this variant is storing. If no object is currently
/// stored (i.e. the `Variant` is invalid), an invalid is returned.
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment