https://gcc.gnu.org/bugzilla/show_bug.cgi?id=89563

            Bug ID: 89563
           Summary: decltype resolution doesn't terminate recursion
           Product: gcc
           Version: 8.2.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: Simon.Richter at hogyros dot de
  Target Milestone: ---

Similar to #88176:

    struct one {};

    struct two
    {
        two() { }
        two(one const &) { }
        operator one() const { return one{}; }
        two operator+(one const &) const { return two{}; }
    };

    two operator+(two const &, two const &) { return two{}; }

    template<typename T>
    auto operator+(T const &lhs, two const &rhs) -> decltype(rhs + lhs)
    {
        return rhs + lhs;
    }

    void test()
    {
        one o;
        two t;
        auto a = o + t;
    }

My original expectation would be that this addition resolves to

    auto operator+<one>(one const &lhs, two const &rhs) -> decltype(rhs + lhs);

where the decltype is resolved through

    two two::operator+(one const &) const;

This doesn't work, due to #88176, so I've provided a freestanding

    two operator+(two const &, two const &);

which terminates the recursion, forcing a conversion through

    two::two(one const &);

This works fine, except if

    two::operator one() const;

also exists, in which case template recursion again exceeds the maximum depth,
so it seems the option to convert the objects back and forth (even though it
would never be selected during overload resolution) makes decltype resolution
go into the infinite recursion.

Reply via email to