Closed tzlaine closed 4 years ago
Your example compiles fine with -stdlib=libc++
. I think the explosion happens with comparing T
and optional<T>
which the libstdc++ version must be using internally.
#include <boost/hana.hpp>
#include <optional>
#include <cassert>
int main() {
boost::hana::tuple<int> x{};
std::optional<boost::hana::tuple<int>> attr;
assert(attr == x); // <-- Kablooey!
<source>:8:17: note: in instantiation of function template specialization 'boost::hana::detail::operators::operator==<std::__1::optional<boost::hana::tuple<int> > &, boost::hana::tuple<int> &, void>' requested here
assert(attr == x); // <-- Kablooey!
boost::hana::detail::operators::operator==<std::__1::optional<boost::hana::tuple<int> > &, boost::hana::tuple<int> &, void>
is being called right off the bat.
Perhaps that operator should fail if the underlying hana::equal
call should fail.
I suggested a similar solution to the same issue with Struct
equality in https://github.com/boostorg/hana/issues/460
Right! Should have mentioned that this was with GCC/libstdc++. I agree with the approach for the fix, but was unable to figure out how to do so -- there's a lot of code around there that is highly interdependent.
Yeah, the tag_of
thing really is the issue.
How about this? https://github.com/boostorg/hana/pull/472
I made those operators not consider types that are the same as their tag type since that is never the case in the Boost.Hana types that use them. (I also fixed the Struct thing)
Yes! That fixed about a million errors I had in some crazy, autogenerated test cases. I peed a little from all the excitement. Thanks, Jason.
Fixed by 4f5157bc425eac8e115d597142932fef2e535282, thanks Jason.
hana/detail/operators/comparable.hpp contains this:
The problem is that
hana::tag_of
is idempotent, and sooperator==(hana::tuple<int>(0), hana::tuple_tag{})
remains a viable overload -- the SFINAE constraint happily considershana::tuple_tag
to be a sequence of some sort -- but then blows up insidehana::equal()
. Withinhana::equal()
, the expressionhana::length(hana::tuple_tag{})
appears, and is ill-formed.This will all happen any time you do
x == y
, wherex
andy
are each ahana::tuple
in astd::optional
. Minimal repro:Best of luck. This is real thorny. I was able to fix it locally, but my fix broke all kinds of stuff not in the immediate path of my changes -- so, no real fix at all.