public inbox for gcc-bugs@sourceware.org
help / color / mirror / Atom feed
* [Bug c/103996] New: Enhancement: Better diagnostic for invalid reuse of a function name
@ 2022-01-12 18:13 nightstrike at gmail dot com
  2022-01-12 18:15 ` [Bug c/103996] " pinskia at gcc dot gnu.org
                   ` (3 more replies)
  0 siblings, 4 replies; 5+ messages in thread
From: nightstrike at gmail dot com @ 2022-01-12 18:13 UTC (permalink / raw)
  To: gcc-bugs

https://gcc.gnu.org/bugzilla/show_bug.cgi?id=103996

            Bug ID: 103996
           Summary: Enhancement: Better diagnostic for invalid reuse of a
                    function name
           Product: gcc
           Version: 12.0
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: nightstrike at gmail dot com
  Target Milestone: ---

Related email thread:
https://gcc.gnu.org/pipermail/gcc-help/2022-January/141117.html

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;
      |       ^

I could not find a compiler option that would tell me what the root cause was. 
I wasn't getting a simple "undeclared" error, so I surmised the name must
already be in use, but I was confused as to how or where it was being used.  My
first thought was that maybe index was a global variable, so I tried using
-Wshadow.  Eventually, I found that it was a function from strings.h which was
included several layers down an include spiral.

I think an effective note from gcc such as "index was previously declared here
as a function", or something similar that often happens in other diagnostics,
would aid in finding the root cause of my bug.

Incidentally, in my actual scenario, the real bug was that I forgot to access
index as a member of a struct: x.index vs index.  But I'd wager that expecting
GCC to look for all nearby structs for a similarly named member is
unreasonable.  Simply telling me where index originates, though, would have
helped greatly.

^ permalink raw reply	[flat|nested] 5+ messages in thread

end of thread, other threads:[~2022-01-13 11:40 UTC | newest]

Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2022-01-12 18:13 [Bug c/103996] New: Enhancement: Better diagnostic for invalid reuse of a function name nightstrike at gmail dot com
2022-01-12 18:15 ` [Bug c/103996] " pinskia at gcc dot gnu.org
2022-01-12 18:23 ` pinskia at gcc dot gnu.org
2022-01-12 18:38 ` [Bug c/103996] Provide " pinskia at gcc dot gnu.org
2022-01-13 11:40 ` egallager at gcc dot gnu.org

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).