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

            Bug ID: 84883
           Summary: No warning when dereferencing an array as a pointer
           Product: gcc
           Version: 8.0.1
            Status: UNCONFIRMED
          Severity: normal
          Priority: P3
         Component: c
          Assignee: unassigned at gcc dot gnu.org
          Reporter: tim.ruehsen at gmx dot de
  Target Milestone: ---

Created attachment 43669
  --> https://gcc.gnu.org/bugzilla/attachment.cgi?id=43669&action=edit
Small test code

It would be nice to a warning (option) if accidentally dereferencing an array
instead of a pointer.

struct BCHAN bchan[5], *bchanp = bchan + 3;
bchanp->x = 1; // that's how it's supposed to be
bchan->x = 1; // arg, typo. but now bchan[0].x has been written

I experienced this in a pretty large codebase. This was causing *very* rare
weird behavior and it's detection was more of a lucky punch.

It is certainly valid C, but what a about an -Warray-deref ?

Reply via email to