Skip site navigation (1)Skip section navigation (2)
Date:      Thu, 17 Jul 2003 13:37:01 +0200 (CEST)
From:      Harti Brandt <brandt@fokus.fraunhofer.de>
To:        Jun Kuriyama <kuriyama@imgsrc.co.jp>
Cc:        Current <freebsd-current@freebsd.org>
Subject:   Re: src/bin/ed/re.c: warning: declaration of `exp' shadows a global declaration
Message-ID:  <20030717133313.X972@beagle.fokus.fraunhofer.de>
In-Reply-To: <7mfzl74f2p.wl@black.imgsrc.co.jp>
References:  <7madbg60b1.wl@black.imgsrc.co.jp> <20030715075429.M34004@beagle.fokus.fraunhofer.de> <7mfzl74f2p.wl@black.imgsrc.co.jp>

next in thread | previous in thread | raw e-mail | index | archive | help

Hi,

here is a somewhat crude hack, that makes the warning go away. It just
prevents the warning if the shadowed symbol is a function and its source
file happens to be "<built-in>". Once a real declaration is seen (as in
math.h) the source file will be the real source file of the declaration
and the warning is emitted. There are sure better ways to do something
like this... And, well, I did not make a world, just checked the example
program.

harti

Index: c-decl.c
===================================================================
RCS file: /home/ncvs/src/contrib/gcc/c-decl.c,v
retrieving revision 1.8
diff -u -r1.8 c-decl.c
--- c-decl.c	11 Jul 2003 05:11:14 -0000	1.8
+++ c-decl.c	17 Jul 2003 11:33:00 -0000
@@ -1637,7 +1637,9 @@
 	    shadow_warning ("a previous local", name, oldlocal);
 	}
       else if (IDENTIFIER_GLOBAL_VALUE (name) != 0
-	       && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node)
+	       && IDENTIFIER_GLOBAL_VALUE (name) != error_mark_node
+	       && (!FUNCTION_TYPE_CHECK(IDENTIFIER_GLOBAL_VALUE(name)) ||
+		strcmp(DECL_SOURCE_FILE(IDENTIFIER_GLOBAL_VALUE(name)), "<built-in>") != 0))
 	shadow_warning ("a global declaration", name,
 			IDENTIFIER_GLOBAL_VALUE (name));
     }

On Wed, 16 Jul 2003, Jun Kuriyama wrote:

JK>At Tue, 15 Jul 2003 11:54:06 -0700,
JK>David O'Brien wrote:
JK>> Much, much better if you can point to the specific GCC source code file
JK>> where this is handled.
JK>
JK>May this help you?
JK>
JK>
JK>waterblue% cat exp.c
JK>int
JK>main(int argc, char** argv)
JK>{
JK>  int exp = 5;
JK>
JK>  return 0;
JK>}
JK>waterblue% cc -Wshadow -c exp.c
JK>exp.c: In function `main':
JK>exp.c:4: warning: declaration of `exp' shadows a global declaration
JK><built-in>:0: warning: shadowed declaration is here
JK>
JK>
JK>

-- 
harti brandt,
http://www.fokus.fraunhofer.de/research/cc/cats/employees/hartmut.brandt/private
brandt@fokus.fraunhofer.de, harti@freebsd.org



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?20030717133313.X972>