Sanitizer says
==3044==ERROR: AddressSanitizer: stack-overflow on address 0x7ffcc58b3ff8 (pc 0x56310c340e84 bp 0x7ffcc58b4000 sp 0x7ffcc58b3ff
0 T0)
#0 0x56310c340e84 in boost::operators_impl::operator==(Testable const&, SomeType const&) /home/sehe/custom/boost_1_75_0/boo
The problem is that Boost's STRONG_TYPEDEF makes the derivative type totally-ordered with the base type:
struct SomeType
: boost::totally_ordered1<SomeType, boost::totally_ordered2<SomeType, Testable>>
{
Testable t;
explicit SomeType(const Testable& t_) noexcept((boost::has_nothrow_copy_constructor<Testable>::value)) : t(t_) {}
SomeType() noexcept( (boost::has_nothrow_default_constructor<Testable>::value)) : t() {}
SomeType(const SomeType& t_) noexcept( (boost::has_nothrow_copy_constructor<Testable>::value)) : t(t_.t) {}
SomeType& operator=(const SomeType& rhs) noexcept((boost::has_nothrow_assign<Testable>::value)) {
t = rhs.t;
return *this;
}
SomeType& operator=(const Testable& rhs) noexcept((boost::has_nothrow_assign<Testable>::value)) {
t = rhs;
return *this;
}
operator const Testable&() const { return t; }
operator Testable&() { return t; }
bool operator==(const SomeType& rhs) const { return t == rhs.t; }
bool operator<(const SomeType& rhs) const { return t < rhs.t; }
};
If you remove that source of implicit conversion:
struct SomeType
: boost::totally_ordered1<SomeType
/*, boost::totally_ordered2<SomeType, Testable>*/>
{
// ...
it JustWorks(TM). I would argue that you should make the conversion operators explicit
as well and always do the casts:
Live On Coliru
#include <boost/serialization/strong_typedef.hpp>
#include <iostream>
enum class Testable { UNDEFINED, A, B };
struct SomeType
: boost::totally_ordered1<SomeType
/*, boost::totally_ordered2<SomeType, Testable>*/>
{
Testable t;
explicit SomeType(const Testable& t_) noexcept((boost::has_nothrow_copy_constructor<Testable>::value)) : t(t_) {}
SomeType() noexcept( (boost::has_nothrow_default_constructor<Testable>::value)) : t() {}
SomeType(const SomeType& t_) noexcept( (boost::has_nothrow_copy_constructor<Testable>::value)) : t(t_.t) {}
SomeType& operator=(const SomeType& rhs) noexcept((boost::has_nothrow_assign<Testable>::value)) {
t = rhs.t;
return *this;
}
SomeType& operator=(const Testable& rhs) noexcept((boost::has_nothrow_assign<Testable>::value)) {
t = rhs;
return *this;
}
explicit operator const Testable&() const { return t; }
explicit operator Testable&() { return t; }
bool operator==(const SomeType& rhs) const { return t == rhs.t; }
bool operator<(const SomeType& rhs) const { return t < rhs.t; }
};
int main() {
SomeType abc{ Testable::UNDEFINED };
std::cout << "START" << std::endl;
if (abc == SomeType{Testable::UNDEFINED}) {
volatile int j = 0;
}
std::cout << "FINISH" << std::endl;
}