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

            Bug ID: 82959
           Summary: g++ doesn't appreciate C++17 evaluation order rules
                    for overloaded operators
           Product: gcc
           Version: 8.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c++
          Assignee: unassigned at gcc dot gnu.org
          Reporter: ixsci at yandex dot ru
  Target Milestone: ---

Having the following code:

#include <iostream>

using namespace std;

class Int
{
public:
    Int() = default;

    Int(int val): 
        m_Value{val}
    {
    }

    Int operator++(int)
    {
        Int tmp{*this};
        ++m_Value;
        return tmp;
    }

    bool operator&&(const Int& rhs) const
    {
        return m_Value && rhs.m_Value;
    }
private:
    int m_Value = 0;
};

template <typename T>
bool cleverFun(T& value)
{
    return (cout << "first\n", value++) && 
        (cout << "second\n", value++);
}

int main()
{
    int i = 0;
    Int complexI{};
    cout << "==========SIMPLE INT============\n";
    cleverFun(i);
    cout << "==========COMPLEX INT============\n";
    cleverFun(complexI);
};

The conforming C++17 compiler (to my knowledge) should output "first" then
"second" twice, but GCC outputs "second" then "first" with the overloaded &&
operator.

Reply via email to