From 43fea763945991d1b83f5c0bb65f12bfab09b99b Mon Sep 17 00:00:00 2001 From: Scott Wilson Date: Mon, 19 Feb 2024 20:33:21 -0800 Subject: [PATCH] int: Allow TypeDesc to have all the right POD attributes (#4162) This PR is for allowing the TypeDesc type to be used directly in a C API without indirection, and therefore also in a Rust API without indirection. --------- Signed-off-by: Scott Wilson --- src/include/OpenImageIO/typedesc.h | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/include/OpenImageIO/typedesc.h b/src/include/OpenImageIO/typedesc.h index 0e0175718e..ab720bfddc 100644 --- a/src/include/OpenImageIO/typedesc.h +++ b/src/include/OpenImageIO/typedesc.h @@ -164,10 +164,7 @@ struct OIIO_UTIL_API TypeDesc { TypeDesc (string_view typestring); /// Copy constructor. - OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept - : basetype(t.basetype), aggregate(t.aggregate), - vecsemantics(t.vecsemantics), reserved(0), arraylen(t.arraylen) - { } + OIIO_HOSTDEVICE constexpr TypeDesc (const TypeDesc &t) noexcept = default; /// Return the name, for printing and whatnot. For example, @@ -365,8 +362,13 @@ struct OIIO_UTIL_API TypeDesc { #endif }; - - +// Validate that TypeDesc can be used directly as POD in a C interface. +static_assert(std::is_default_constructible(), "TypeDesc is not default constructable."); +static_assert(std::is_trivially_copyable(), "TypeDesc is not trivially copyable."); +static_assert(std::is_trivially_destructible(), "TypeDesc is not trivially destructible."); +static_assert(std::is_trivially_move_constructible(), "TypeDesc is not move constructible."); +static_assert(std::is_trivially_copy_constructible(), "TypeDesc is not copy constructible."); +static_assert(std::is_trivially_move_assignable(), "TypeDesc is not move assignable."); // Static values for commonly used types. Because these are constexpr, // they should incur no runtime construction cost and should optimize nicely