src/bin/ed/re.c: warning: declaration of `exp' shadows a global declaration

Harti Brandt brandt at fokus.fraunhofer.de
Thu Jul 17 04:37:10 PDT 2003


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 at fokus.fraunhofer.de, harti at freebsd.org


More information about the freebsd-current mailing list