The C++ standard contains a semi-famous example of \"surprising\" name lookup in 3.3.2, \"Point of declaration\":
int x = x;
This initializ
The behavior is not undefined. The variable is uninitialized and stays with whatever random value uninitialized values start up with. One example from clan'g test suit:
int test7b(int y) {
int x = x; // expected-note{{variable 'x' is declared here}}
if (y)
x = 1;
// Warn with "may be uninitialized" here (not "is sometimes uninitialized"),
// since the self-initialization is intended to suppress a -Wuninitialized
// warning.
return x; // expected-warning{{variable 'x' may be uninitialized when used here}}
}
Which you can find in clang/test/Sema/uninit-variables.c tests for this case explicitly.