From 3bc54e51713a22d7706393fdc73385bac6979943 Mon Sep 17 00:00:00 2001 From: Roland Conybeare Date: Wed, 4 Mar 2026 14:04:17 +1100 Subject: [PATCH] xo-facet: need assert in boolean logic for invalid corner case --- xo-facet/include/xo/facet/OObject.hpp | 18 ++++++++++++------ xo-facet/include/xo/facet/obj.hpp | 2 +- 2 files changed, 13 insertions(+), 7 deletions(-) diff --git a/xo-facet/include/xo/facet/OObject.hpp b/xo-facet/include/xo/facet/OObject.hpp index 6d14cf91..c121e5ee 100644 --- a/xo-facet/include/xo/facet/OObject.hpp +++ b/xo-facet/include/xo/facet/OObject.hpp @@ -10,6 +10,7 @@ #include #include #include +#include namespace xo { namespace facet { @@ -198,19 +199,24 @@ namespace xo { * - assigning from pointer with compatible representation * - implementing the fat-object-pointer equivalent of * assigning a derived pointer to a base pointer. + * - making a mistake (attempting to assign incompatible representations) **/ template OObject & from_data(DOther * other) { static_assert(std::is_same_v || std::is_convertible_v); - if constexpr (!std::is_same_v - && std::is_convertible_v) + if constexpr (!std::is_same_v) { - /* assigning to typed data, from something with consistent - * representation keep .iface_ pointer - */ - this->data_ = other; + if (std::is_convertible_v) { + /* assigning to typed data, from something with consistent + * representation. keeping .iface_ pointer + */ + this->data_ = other; + } else { + /** DOther not compatible with DRepr. conversion is bad **/ + assert(false); + } } else /*DRepr is DVariantPlaceholder*/ { /** assigning to variant * diff --git a/xo-facet/include/xo/facet/obj.hpp b/xo-facet/include/xo/facet/obj.hpp index ada5c832..d16c776c 100644 --- a/xo-facet/include/xo/facet/obj.hpp +++ b/xo-facet/include/xo/facet/obj.hpp @@ -138,7 +138,7 @@ namespace xo { obj to_facet(); /** like to_facet(), - * but on failure return empty obj instead of throwing exception + * but on failure return empty obj instead of throwing exception **/ template obj try_to_facet() noexcept;