public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/23846] New: suggest new warning (example: int x = x)
@ 2005-09-13 3:44 ash at onezero dot org
2005-09-13 3:48 ` [Bug c/23846] " pinskia at gcc dot gnu dot org
2005-09-13 4:08 ` ash at onezero dot org
0 siblings, 2 replies; 3+ messages in thread
From: ash at onezero dot org @ 2005-09-13 3:44 UTC (permalink / raw)
To: gcc-bugs
gcc -std=c99 -Wall gives no errors or warnings when an initialization (right
side of =) refers to the value being initialized (left side of =). This is
true if the item being dereferenced has an indeterminate value, e.g., is a
local variable:
| cat t.c
#include <stdio.h>
int main()
{
int array[] = { 1, 2 };
int x = 0;
int y = array[y];
printf("x=%d y=%d", x, y);
}
| gcc --version
gcc (GCC) 3.3.3 (cygwin special)
Copyright (C) 2003 Free Software Foundation, Inc.
This is free software; see the source for copying conditions. There is NO
warranty; not even for MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
| gcc -Wall -std=c99 -o t t.c
| ./t
x=0 y=1
|
In this case the programmer made a mistake and meant to use "array[x]" in the
initialization of y.
I just found this in my own code - it is an easy mistake to make when doing a
mass transformation of code. I was lucky because the line generated a bus
error, but this error could be insidious because the code could work in some
environments.
My guess is that the vast majority of cases where the lvalue being initialized
is deferenced on the right side of an initialization are mistakes. If this is
permitted by the standard, presumably to ease doing things like "int* x = &x",
then maybe a new warning could be created (probably "on" by default, or part
of "-Wall").
--
Summary: suggest new warning (example: int x = x)
Product: gcc
Version: 3.3.1
Status: UNCONFIRMED
Severity: enhancement
Priority: P1
Component: c
AssignedTo: unassigned at gcc dot gnu dot org
ReportedBy: ash at onezero dot org
CC: gcc-bugs at gcc dot gnu dot org
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23846
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/23846] suggest new warning (example: int x = x)
2005-09-13 3:44 [Bug c/23846] New: suggest new warning (example: int x = x) ash at onezero dot org
@ 2005-09-13 3:48 ` pinskia at gcc dot gnu dot org
2005-09-13 4:08 ` ash at onezero dot org
1 sibling, 0 replies; 3+ messages in thread
From: pinskia at gcc dot gnu dot org @ 2005-09-13 3:48 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From pinskia at gcc dot gnu dot org 2005-09-13 03:48 -------
Already fixed in 3.4.0 and above with -O1 -Wuninitialized.
If you have really int x = x; use -Winit-self and then you will get a warning there too.
--
What |Removed |Added
----------------------------------------------------------------------------
Status|UNCONFIRMED |RESOLVED
Resolution| |FIXED
Target Milestone|--- |3.4.0
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23846
^ permalink raw reply [flat|nested] 3+ messages in thread
* [Bug c/23846] suggest new warning (example: int x = x)
2005-09-13 3:44 [Bug c/23846] New: suggest new warning (example: int x = x) ash at onezero dot org
2005-09-13 3:48 ` [Bug c/23846] " pinskia at gcc dot gnu dot org
@ 2005-09-13 4:08 ` ash at onezero dot org
1 sibling, 0 replies; 3+ messages in thread
From: ash at onezero dot org @ 2005-09-13 4:08 UTC (permalink / raw)
To: gcc-bugs
------- Additional Comments From ash at onezero dot org 2005-09-13 04:08 -------
I'll look forward to trying it out..
I've got to figure out a way to get gcc 4. I wish gcc 4 was available with
Cygwin.
--
http://gcc.gnu.org/bugzilla/show_bug.cgi?id=23846
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2005-09-13 4:08 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-09-13 3:44 [Bug c/23846] New: suggest new warning (example: int x = x) ash at onezero dot org
2005-09-13 3:48 ` [Bug c/23846] " pinskia at gcc dot gnu dot org
2005-09-13 4:08 ` ash at onezero dot org
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).