[Bug c++/110850] Evaluation order of assignment operands

sergio_nsk at yahoo dot de gcc-bugzilla@gcc.gnu.org
Tue Dec 9 07:42:32 GMT 2025


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

Sergey Markelov <sergio_nsk at yahoo dot de> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |sergio_nsk at yahoo dot de

--- Comment #1 from Sergey Markelov <sergio_nsk at yahoo dot de> ---
Yet another evaluation order violation in the simple assignment.

#include <array>
#include <iostream>

using std::array;
using std::cout;

array<int, 1> a;

array<int, 1>& f() {
  cout << "f ";
  return a;
}

int g() {
  cout << "g ";
  return 0;
}

int main() { f() = {{g()}}; }

Actual output:   f g
Expected output: g f

All modern GCC versions and trunk are affected.

Compiler Explorer: https://godbolt.org/z/qr8TKT4Tq
Stack Overflow: https://stackoverflow.com/q/79841435/6752050


More information about the Gcc-bugs mailing list