* Better diagnostic for shadowed function?
@ 2022-01-12 6:33 NightStrike
2022-01-12 8:32 ` Xi Ruoyao
2022-01-12 10:06 ` Jonathan Wakely
0 siblings, 2 replies; 4+ messages in thread
From: NightStrike @ 2022-01-12 6:33 UTC (permalink / raw)
To: gcc-help
I recently hit this problem:
#include <strings.h>
void f() {
index[0] = 0;
}
#gcc is 11.2.0
gcc -c a.c
a.c:4:7: error: subscripted value is neither array nor pointer nor vector
4 | index[1] = 0;
| ^
-Wshadow (or all or extra) did not highlight that "index" was actually
a function from strings.h. For the future, is there anything I could
have done to make gcc tell me what the real error was?
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Better diagnostic for shadowed function?
2022-01-12 6:33 Better diagnostic for shadowed function? NightStrike
@ 2022-01-12 8:32 ` Xi Ruoyao
2022-01-12 10:06 ` Jonathan Wakely
1 sibling, 0 replies; 4+ messages in thread
From: Xi Ruoyao @ 2022-01-12 8:32 UTC (permalink / raw)
To: NightStrike, gcc-help
On Wed, 2022-01-12 at 01:33 -0500, NightStrike via Gcc-help wrote:
> I recently hit this problem:
>
> #include <strings.h>
> void f() {
> index[0] = 0;
> }
>
> #gcc is 11.2.0
> gcc -c a.c
> a.c:4:7: error: subscripted value is neither array nor pointer nor
> vector
> 4 | index[1] = 0;
> | ^
>
> -Wshadow (or all or extra) did not highlight that "index" was actually
> a function from strings.h.
It has nothing to do with -Wshadow, because nothing is shadowed.
> For the future, is there anything I could
> have done to make gcc tell me what the real error was?
Open an issue in https://gcc.gnu.org/bugzilla and hope someone will pick
it up :).
--
Xi Ruoyao <xry111@mengyan1223.wang>
School of Aerospace Science and Technology, Xidian University
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Better diagnostic for shadowed function?
2022-01-12 6:33 Better diagnostic for shadowed function? NightStrike
2022-01-12 8:32 ` Xi Ruoyao
@ 2022-01-12 10:06 ` Jonathan Wakely
2022-01-12 18:36 ` NightStrike
1 sibling, 1 reply; 4+ messages in thread
From: Jonathan Wakely @ 2022-01-12 10:06 UTC (permalink / raw)
To: NightStrike; +Cc: gcc-help
On Wed, 12 Jan 2022 at 06:34, NightStrike via Gcc-help
<gcc-help@gcc.gnu.org> wrote:
>
> I recently hit this problem:
>
> #include <strings.h>
> void f() {
> index[0] = 0;
> }
>
> #gcc is 11.2.0
> gcc -c a.c
> a.c:4:7: error: subscripted value is neither array nor pointer nor vector
> 4 | index[1] = 0;
> | ^
>
> -Wshadow (or all or extra) did not highlight that "index" was actually
> a function from strings.h. For the future, is there anything I could
> have done to make gcc tell me what the real error was?
g++ is *slightly* more help:
s.c:3:10: error: invalid types ‘<unresolved overloaded function
type>[int]’ for array subscript
This at least gives you a hint it's a function, so probably declared
somewhere in a header. The C front end could do the same, saying
"subscripted value is a function", but it just has a generic
diagnostic for all un-subscriptable types. Asking for that to be
improved seems like a good use of a bugzilla PR.
Maybe would make sense for us to also add a note telling you where
'index' was declared, as long as it doesn't get suppressed without
-Wsystem-headers !
^ permalink raw reply [flat|nested] 4+ messages in thread
* Re: Better diagnostic for shadowed function?
2022-01-12 10:06 ` Jonathan Wakely
@ 2022-01-12 18:36 ` NightStrike
0 siblings, 0 replies; 4+ messages in thread
From: NightStrike @ 2022-01-12 18:36 UTC (permalink / raw)
To: Jonathan Wakely; +Cc: gcc-help
On Wed, Jan 12, 2022 at 5:06 AM Jonathan Wakely <jwakely.gcc@gmail.com> wrote:
>
> On Wed, 12 Jan 2022 at 06:34, NightStrike via Gcc-help
> <gcc-help@gcc.gnu.org> wrote:
> >
> > I recently hit this problem:
> >
> > #include <strings.h>
> > void f() {
> > index[0] = 0;
> > }
> >
> > #gcc is 11.2.0
> > gcc -c a.c
> > a.c:4:7: error: subscripted value is neither array nor pointer nor vector
> > 4 | index[1] = 0;
> > | ^
> >
> > -Wshadow (or all or extra) did not highlight that "index" was actually
> > a function from strings.h. For the future, is there anything I could
> > have done to make gcc tell me what the real error was?
>
> g++ is *slightly* more help:
> s.c:3:10: error: invalid types ‘<unresolved overloaded function
> type>[int]’ for array subscript
>
> This at least gives you a hint it's a function, so probably declared
> somewhere in a header. The C front end could do the same, saying
> "subscripted value is a function", but it just has a generic
> diagnostic for all un-subscriptable types. Asking for that to be
> improved seems like a good use of a bugzilla PR.
>
> Maybe would make sense for us to also add a note telling you where
> 'index' was declared, as long as it doesn't get suppressed without
> -Wsystem-headers !
Added as https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103996
Thanks!
^ permalink raw reply [flat|nested] 4+ messages in thread
end of thread, other threads:[~2022-01-12 18:36 UTC | newest]
Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 6:33 Better diagnostic for shadowed function? NightStrike
2022-01-12 8:32 ` Xi Ruoyao
2022-01-12 10:06 ` Jonathan Wakely
2022-01-12 18:36 ` NightStrike
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).