xo-facet: need assert in boolean logic for invalid corner case

This commit is contained in:
Roland Conybeare 2026-03-04 14:04:17 +11:00
commit 3bc54e5171
2 changed files with 13 additions and 7 deletions

View file

@ -10,6 +10,7 @@
#include <new>
#include <cstring>
#include <cstddef>
#include <cassert>
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 <typename DOther>
OObject & from_data(DOther * other) {
static_assert(std::is_same_v<DRepr, DVariantPlaceholder>
|| std::is_convertible_v<DOther*, DRepr*>);
if constexpr (!std::is_same_v<DRepr, DVariantPlaceholder>
&& std::is_convertible_v<DOther*, DRepr*>)
if constexpr (!std::is_same_v<DRepr, DVariantPlaceholder>)
{
/* assigning to typed data, from something with consistent
* representation keep .iface_ pointer
*/
this->data_ = other;
if (std::is_convertible_v<DOther*, DRepr*>) {
/* 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
*

View file

@ -138,7 +138,7 @@ namespace xo {
obj<AOther,DRepr> to_facet();
/** like to_facet<AOther>(),
* but on failure return empty obj instead of throwing exception
* but on failure return empty obj instead of throwing exception
**/
template <typename AOther>
obj<AOther,DRepr> try_to_facet() noexcept;