Re: [PATCH 18/348] Fix -Wsahdow warnings

Mark Kettenis
2011-11-27T13:53:35Z

> Date: Fri, 25 Nov 2011 20:19:55 +0200
> From: Eli Zaretskii <eliz@gnu.org>
>
> > Date: Fri, 25 Nov 2011 17:26:04 +0100 (CET)
> > From: Mark Kettenis <mark.kettenis@xs4all.nl>
> > CC: brobecker@adacore.com, andrew.smirnov@gmail.com,
> > gdb-patches@sourceware.org
> >
> > Since there is absolutely no problem with a local variable that has
> > the same name as a library function, this is bad.
>
> You are, in effect, saying that the wisdom of coding "down the middle
> of a programming language" is wrong. We will have to disagree on
> that, sorry. FWIW, I don't think a large project should live
> dangerously just because some versions of some compiler will flag
> these clashes even without -Wshadow.

I think you're still missing my point.

What I'm saying is that a local variable shadowing a function is never
a problem. It would only be a problem if inside the function that has
the local variable, you'd (accidentally) try to invoke the function.
That's why I came up with the example:

void foo(void);

void
bar(void)
{
int foo;

foo();
}

where the function foo() is being called when it is being shadowed by
a local variable. This won't compile on *any* C compiler, simply
because it isn't legal C.