GCC Bugzilla has been upgraded from version 4.4.9 to 5.0rc3. If you see any problem, please report it to bug 64968.
Bug 5582 - warn about using the extension "int x=x;"
Summary: warn about using the extension "int x=x;"
Status: RESOLVED FIXED
Alias: None
Product: gcc
Classification: Unclassified
Component: c (show other bugs)
Version: 3.0.3
: P3 enhancement
Target Milestone: 3.4.0
Assignee: Andrew Pinski
URL:
Keywords: diagnostic, documentation
: 7781 8371 12153 24157 (view as bug list)
Depends on:
Blocks:
 
Reported: 2002-02-04 11:06 UTC by coola
Modified: 2005-10-01 15:40 UTC (History)
4 users (show)

See Also:
Host:
Target:
Build:
Known to work:
Known to fail:
Last reconfirmed:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description coola 2002-02-04 11:06:03 UTC
gcc never warns of probable mistake when feed a line
like the following:

    int x = x;

concluding the discussion on the GCC ML. gcc should emit a
warning when invoke with `-Wall' and be silent when run
with `-Wall -Wno-<warning name>'

Release:
3.0.3

Environment:
any

How-To-Repeat:
compile:
    int x = x;
Comment 1 Wolfgang Bangerth 2003-01-07 17:12:05 UTC
State-Changed-From-To: open->analyzed
State-Changed-Why: The use of
      int x = x;
    is a gcc extension, but I could indeed not find a place in
    the manual that talks about a warning option that gives
    a message when this extension is used.
Comment 2 Wolfgang Bangerth 2003-01-08 08:24:46 UTC
From: Wolfgang Bangerth <bangerth@ticam.utexas.edu>
To: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
Cc: pcarlini@unitus.it, <aoliva@redhat.com>, <dewar@gnat.com>,
   <gcc-gnats@gcc.gnu.org>, <coola@ngs.ru>, <gcc-bugs@gcc.gnu.org>,
   <bangerth@dealii.org>
Subject: Re: c/5582: warn about using the extension "int x=x;"
Date: Wed, 8 Jan 2003 08:24:46 -0600 (CST)

 > You get no error/warning, if you try to compile the code inside a
 > function, ie. "void foo() { int x=x; }".
 > But that's not a gcc extension, just a missing warning about the use of
 > an uninitialized variable.
 
 Sure. IIRC the extension is that this reliably calms down warnings about 
 uninitialized variables.
 
 W.
 
 -------------------------------------------------------------------------
 Wolfgang Bangerth             email:            bangerth@ticam.utexas.edu
                               www: http://www.ticam.utexas.edu/~bangerth/
Comment 3 Volker Reichelt 2003-01-08 12:50:22 UTC
From: Volker Reichelt <reichelt@igpm.rwth-aachen.de>
To: pcarlini@unitus.it, aoliva@redhat.com, dewar@gnat.com,
        gcc-gnats@gcc.gnu.org, coola@ngs.ru, gcc-bugs@gcc.gnu.org,
        bangerth@dealii.org
Cc:  
Subject: Re: c/5582: warn about using the extension "int x=x;"
Date: Wed, 8 Jan 2003 12:50:22 +0100

 Just for the sake of completeness:
 gcc issues an error if you just try to compile "int x=x;".
 
 You get no error/warning, if you try to compile the code inside a
 function, ie. "void foo() { int x=x; }".
 But that's not a gcc extension, just a missing warning about the use of
 an uninitialized variable.
 
 Regards,
 Volker
 
 http://gcc.gnu.org/cgi-bin/gnatsweb.pl?cmd=view%20audit-trail&database=gcc&pr=5582
 
 

Comment 4 Andrew Pinski 2003-08-07 04:24:12 UTC
I am working on a patch.
Comment 5 Andrew Pinski 2003-08-17 05:08:52 UTC
I submitted a patch to fix this only when -pedantic is supplied: <http://gcc.gnu.org/ml/gcc-
patches/2003-08/msg00952.html>.  We should document this also.  I will submit a patch 
to add this documentation later today.
Comment 6 CVS Commits 2003-08-19 20:29:05 UTC
Subject: Bug 5582

CVSROOT:	/cvs/gcc
Module name:	gcc
Changes by:	pinskia@gcc.gnu.org	2003-08-19 20:29:01

Modified files:
	gcc            : c-common.h c.opt c-opts.c c-lang.c function.c 
	gcc/objc       : objc-lang.c 
	gcc/doc        : invoke.texi 
	gcc/cp         : cp-lang.c 

Log message:
	PR c++/10538, PR c/5582
	
	ChangeLog:
	* langhooks-def.h (lhd_decl_uninit): Declare.
	(LANG_HOOKS_DECL_UNINIT): New macro.
	(LANG_HOOKS_INITIALIZER): Adjust.
	* langhooks.h (struct lang_hooks): Add new field
	decl_uninit.
	* langhooks.c (lhd_decl_uninit): Define.
	* c-common.c (c_decl_uninit_1): New function.
	(c_decl_uninit): New function.
	(warn_init_self): Define.
	* c-common.h (c_decl_uninit): Declare.
	(warn_init_self): Declare.
	* c.opt: Introduce -Winit-self.
	* c-opts.c (c_common_handle_options): Set warn_init_self.
	* c-lang.c (LANG_HOOKS_DECL_UNINIT): Define.
	* objc/objc-lang.c  (LANG_HOOKS_DECL_UNINIT): Define.
	* function.c (uninitialized_vars_warning): Call the language hook.
	* doc/invoke.texi: Document -Winit-self.
	
	cp/ChangeLog:
	* cp/cp-lang.c (LANG_HOOKS_DECL_UNINIT): Define.
	
	testsuite:
	* gcc.dg/uninit-D.c: New Test.
	* gcc.dg/uninit-E.c: New Test.
	* gcc.dg/uninit-F.c: New Test.
	* gcc.dg/uninit-G.c: New Test.

Patches:
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-common.h.diff?cvsroot=gcc&r1=1.202&r2=1.203
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c.opt.diff?cvsroot=gcc&r1=1.14&r2=1.15
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-opts.c.diff?cvsroot=gcc&r1=1.87&r2=1.88
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/c-lang.c.diff?cvsroot=gcc&r1=1.114&r2=1.115
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/function.c.diff?cvsroot=gcc&r1=1.449&r2=1.450
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/objc/objc-lang.c.diff?cvsroot=gcc&r1=1.37&r2=1.38
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/doc/invoke.texi.diff?cvsroot=gcc&r1=1.328&r2=1.329
http://gcc.gnu.org/cgi-bin/cvsweb.cgi/gcc/gcc/cp/cp-lang.c.diff?cvsroot=gcc&r1=1.61&r2=1.62

Comment 7 Andrew Pinski 2003-08-19 20:33:58 UTC
Fixed on the mainline for 3.4 use -Winit-self for the warning.
Comment 8 Andrew Pinski 2003-10-16 21:47:33 UTC
*** Bug 12153 has been marked as a duplicate of this bug. ***
Comment 9 Andrew Pinski 2005-10-01 15:40:42 UTC
*** Bug 24157 has been marked as a duplicate of this bug. ***