Hi, the following should probably produce warning at least with -Wall. void foo(void) { int a = a; }
This is/was documented as a way to get rid of uninitialized warnings. So if this changes, please change the documentation too. Also -Wself-init should cause the initialized warnings to come back. Note I implemented that option which is why I know some of the history around it. Note also there is another bug requesting the option be enabled by default too.
(In reply to Andrew Pinski from comment #1) > This is/was documented as a way to get rid of uninitialized warnings. So if > this changes, please change the documentation too. Also -Wself-init should > cause the initialized warnings to come back. Note I implemented that option > which is why I know some of the history around it. > > Note also there is another bug requesting the option be enabled by default > too. bug 52167?
Clang has diagnosed the following with -Wuninitialized (included in -Wall) since at least version 3.0: int foo(void) { int a = a; return a; } GCC requires -Winit-self to diagnose this bug. Neither diagnoses the test case in comment #0 (the initialization is eliminated and the variable is unused). I suppose this could be viewed as a duplicate of pr52167 but that request (and all its duplicates) is specific to C++ and classes with ctors where the fix I suspect is substantially more involved than just flipping -Winit-self on. With that I think it makes sense to treat this as separate. Confirmed.
bug 53129 is also at least somewhat related
*** Bug 112739 has been marked as a duplicate of this bug. ***
Actually this is documented from https://gcc.gnu.org/onlinedocs/gcc-13.2.0/gcc/Warning-Options.html#index-Wuninitialized: If you want to warn about code that uses the uninitialized value of the variable in its own initializer, use the -Winit-self option. Which has been documented this way since -Wself-init was added back in r0-52301-g3390f9c9bef0be . So this is again folks not reading the documentation.