* -Wshadow=retroactive-parameter
@ 2026-10-23 21:34 Alejandro Colomar
0 siblings, 0 replies; only message in thread
From: Alejandro Colomar @ 2026-10-23 21:34 UTC (permalink / raw)
To: gcc
Cc: Mark Harris, Michael Kerrisk, Christopher Bazley, Sam James,
Carlos O'Donell, Joseph S. Myers, Martin Uecker,
Guillem Jover, g.branden.robinson, Günther Noack,
Ahelenia Ziemiańska, linux-man
[-- Attachment #1: Type: text/plain, Size: 1596 bytes --]
Hi!
I'm worried about some proposal going on in the C Committee at the
moment, and which I've also received for the manual pages.
Some people would like manual pages to use retroactive declarations of
parameters. I fear that would cause all kinds of bugs if programmers
see that syntax and believe it's valid and has the intuitive meaning,
but then compile it and get behavior that might not be what they want.
In particular, I'm worried that this might happen rather often in the
near future:
alx@debian:~/tmp$ cat param.c
int
main(void)
{
int n = 42;
int f(char a[n], int n)
{
return _Countof(a);
}
char s[] = "foo";
return f(s, _Countof(s));
}
alx@debian:~/tmp$ /opt/local/gnu/gcc/cap/bin/gcc -Wall -Wextra param.c
param.c: In function ‘f’:
param.c:6:30: warning: unused parameter ‘n’ [-Wunused-parameter]
6 | int f(char a[n], int n)
| ~~~~^
alx@debian:~/tmp$ ./a.out; echo $?
42
I would be interested in having a new subflag
-Wshadow=retroactive-parameter, which triggers when a parameter is
shadowing a previous variable and that variable has been used previously
in the same parameter declaration list in which the shadowing parameter
is being declared (but before the shadowing occurs).
This should be part of -Wextra (at least), as it's rather dangerous, and
shouldn't break any existing code (if it triggers, the code is likely
bad).
This would remove my concerns about it.
Have a lovely night!
Alex
--
<https://www.alejandro-colomar.es>
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 833 bytes --]
^ permalink raw reply [flat|nested] only message in thread
only message in thread, other threads:[~2026-10-23 21:34 UTC | newest]
Thread overview: (only message) (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2026-10-23 21:34 -Wshadow=retroactive-parameter Alejandro Colomar
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox