int test[2] = { 45, test[0] };
int x = (x = 111);
cout << test[0] << " " << test[1] << " " << x << "\n"; // 45 45 111
Are the assignments in the first two lines legal? Visual Studio 2010 compiles and runs it without any errors or warnings but it seems like an odd case that could possibly be undefined, so I wanted to confirm that it is acceptable. Visual Studio does warn me if I do something blatantly reflexive (and presumably undefined) like int x = x; so I’m wondering how these situations it seems to allow are handled.
From the C++ Standard (C++11, but it wasn’t different in C++98/03):
This applies to user-defined types as well as array-types as well. Notice how the Standard emphasizes that
xin the second example is initialised with an indeterminate value. So there is no way to know what valuexis initialised with.