Bug 91225 - Warning should be produced for a variable initialized by itself at the declaration
Summary: Warning should be produced for a variable initialized by itself at the declar...
Status: RESOLVED INVALID
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: unknown
: P3 normal
Target Milestone: ---
Assignee: Not yet assigned to anyone
URL:
Keywords: documentation
: 112739 (view as bug list)
Depends on:
Blocks:
 
Reported: 2019-07-22 13:40 UTC by Jan Hubicka
Modified: 2023-11-27 23:52 UTC (History)
3 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed: 2019-07-22 00:00:00


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Jan Hubicka 2019-07-22 13:40:05 UTC
Hi,
the following should probably produce warning at least with -Wall.

void foo(void)
{
int a = a;
}
Comment 1 Andrew Pinski 2019-07-22 13:46:19 UTC
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.
Comment 2 Eric Gallager 2019-07-22 15:56:57 UTC
(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?
Comment 3 Martin Sebor 2019-07-22 16:32:11 UTC
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.
Comment 4 Eric Gallager 2019-07-22 16:54:17 UTC
bug 53129 is also at least somewhat related
Comment 5 Andrew Pinski 2023-11-27 23:44:39 UTC
*** Bug 112739 has been marked as a duplicate of this bug. ***
Comment 6 Andrew Pinski 2023-11-27 23:52:49 UTC


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.