ARTICLE AD BOX
Running the following code
#include <array> #include <iostream> using namespace std; array<int, 2> a; array<int, 2>& f() { cout << "f" << endl; return a; } int g(int const x) { cout << "g " << x << endl; return x; } int main() { f() = { g(1), g(2) }; }prints
f g 1 g 2with certain configurations of g++. (Compiler Explorer)
Reading evaluation order on cppreference,
In every simple assignment expression E1 = E2 and every compound assignment expression E1 @= E2, E2 is sequenced before E1. (since C++17)I would expect f to be printed last.
(Alternatatively, see C++ Standard [expr.assign.1].)
What am I misunderstanding?
