Just performed a technical interview and during one of the discussions the candidate end up with the following code in codepad: struct S { int x = x; };
A bit to my surprise it compiled successfully with the codepad built-in GCC 12.
Then I was wondering what does that even mean.
It turns out that in C++20 this is a syntactically correct designated initializer for a non-union aggregate. And no one explicitly forbids it from being self-referential!
So basically that's attempt to assign the x value to the same x. Before it was initialized. And yes, that's possible, and yes, that's UB.
The more I see C++ code the more I grow an opinion "You can type any random string into modern C++ compiler and it would compile successfully. And it will contain at least one UB."