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

Harti Brandt brandt at fokus.fraunhofer.de
Mon Jul 14 22:59:51 PDT 2003


On Tue, 15 Jul 2003, Jun Kuriyama wrote:

JK>
JK>With new gcc and -Wshadow, src/bin/ed/re.c shows this warning:
JK>
JK>cc -Wshadow -c re.c
JK>re.c: In function `get_compiled_pattern':
JK>re.c:44: warning: declaration of `exp' shadows a global declaration
JK><built-in>:0: warning: shadowed declaration is here
JK>
JK>It seems local variable exp is conflicted with exp(3) declaration.  I
JK>don't know what name should be used...

I would call this a compiler bug. It shouldn't declare exp(3) when you
don't include math.h. As I understand the standard the names in math.h are
only reserved when you include math.h. I remember that an earlier version
of gcc had this bug, that was fixed then. Probably they unfixed it again.

What's the chance of getting this fixed?

harti

JK>
JK>
JK>Index: re.c
JK>===================================================================
JK>RCS file: /home/ncvs/src/bin/ed/re.c,v
JK>retrieving revision 1.19
JK>diff -u -r1.19 re.c
JK>--- re.c	30 Jun 2002 05:13:53 -0000	1.19
JK>+++ re.c	14 Jul 2003 23:42:41 -0000
JK>@@ -41,7 +41,7 @@
JK> pattern_t *
JK> get_compiled_pattern(void)
JK> {
JK>-	static pattern_t *exp = NULL;
JK>+	static pattern_t *expr = NULL;
JK> 	static char error[1024];
JK>
JK> 	char *exps;
JK>@@ -52,27 +52,27 @@
JK> 		errmsg = "invalid pattern delimiter";
JK> 		return NULL;
JK> 	} else if (delimiter == '\n' || *++ibufp == '\n' || *ibufp == delimiter) {
JK>-		if (!exp)
JK>+		if (!expr)
JK> 			errmsg = "no previous pattern";
JK>-		return exp;
JK>+		return expr;
JK> 	} else if ((exps = extract_pattern(delimiter)) == NULL)
JK> 		return NULL;
JK> 	/* buffer alloc'd && not reserved */
JK>-	if (exp && !patlock)
JK>-		regfree(exp);
JK>-	else if ((exp = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) {
JK>+	if (expr && !patlock)
JK>+		regfree(expr);
JK>+	else if ((expr = (pattern_t *) malloc(sizeof(pattern_t))) == NULL) {
JK> 		fprintf(stderr, "%s\n", strerror(errno));
JK> 		errmsg = "out of memory";
JK> 		return NULL;
JK> 	}
JK> 	patlock = 0;
JK>-	if ((n = regcomp(exp, exps, 0))) {
JK>-		regerror(n, exp, error, sizeof error);
JK>+	if ((n = regcomp(expr, exps, 0))) {
JK>+		regerror(n, expr, error, sizeof error);
JK> 		errmsg = error;
JK>-		free(exp);
JK>-		return exp = NULL;
JK>+		free(expr);
JK>+		return expr = NULL;
JK> 	}
JK>-	return exp;
JK>+	return expr;
JK> }
JK>
JK>
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