This is the mail archive of the
gcc-patches@gcc.gnu.org
mailing list for the GCC project.
Re: [PATCH] Fix -Wshadow=local warnings in genautomata.c
On Wed, Oct 16, 2019 at 09:43:49AM -0600, Martin Sebor wrote:
> Should the warning trigger when the shadowing name results from
> macro expansion? The author of a macro can't (in general) know
> what context it's going to be used, and when different macros
> come from two different third party headers, it would seem
> pointless to force their users to jump through hoops just to
> avoid the innocuous shadowing. Such as in this example:
>
> #define Abs(x) \
> __extension__ (({ __typeof__ (x) _x = x; _x < 0 ? -_x : _x; }))
>
> #define Min(x, y) \
> __extension__ (({ __typeof__ (x) _x = x; __typeof__ (y) _y = y; _x < _y ?
> _x : _y; }))
>
> int f (int x, int y)
> {
> return Abs (Min (x, y)); // -Wshadow for _x?
> }
The counter example would be:
#define F(x) \
__extension__ (({ __typeof__ (x) _x = x; _x < 0 ? -_x : _x; }))
#define G(x) \
__extension__ (({ __typeof__ (x) _x = x; F(_x); }))
where a -Wshadow diagnostics could point the author at a serious bug,
because in the expansion it will be __typeof__ (_x) _x = _x; ...
Jakub