https://gcc.gnu.org/bugzilla/show_bug.cgi?id=97288
Bug ID: 97288 Summary: Assignment sequence before order - evaluating reference to value of right side not in order Product: gcc Version: 10.2.0 Status: UNCONFIRMED Severity: normal Priority: P3 Component: c++ Assignee: unassigned at gcc dot gnu.org Reporter: kirshamir at gmail dot com Target Milestone: --- Following code results with different result in gcc and clang, seems that gcc get wrong the sequence before: class Number { int num = 0; public: Number(int n): num(n) { std::cout << "in ctor of Number for: " << num << std::endl; } // Number(const Number& n): num(n.num) { // std::cout << "in copy of Number for: " << num << std::endl; // } Number& operator+=(int i) { std::cout << "in +=(int) for *this = " << num << " and int = " << i << std::endl; num += i; return *this; } Number& operator+=(Number n) { std::cout << "in +=(Number) for *this = " << num << " and Number = " << n << std::endl; num += n.num; return *this; } operator int() const { return num; } }; int main() { Number a {5}; (a += 1) += a; std::cout << a << std::endl; } Code: https://godbolt.org/z/1P63z7 Based on stackoverflow: https://stackoverflow.com/questions/64195482/chained-compound-assignments-with-c17-sequencing-are-still-undefined-behaviour