This is the mail archive of the gcc-bugs@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[Bug c/67882] surprising offsetof result on an invalid array member without diagnostic


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

Martin Sebor <msebor at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
             Status|SUSPENDED                   |RESOLVED
         Resolution|---                         |FIXED

--- Comment #10 from Martin Sebor <msebor at gcc dot gnu.org> ---
The sentiment within WG14 about the question raised in comment #5 was that the
use case is invalid and the offsetof description makes it sufficiently clear. 
In

  struct s {
    int fpr[32][1];
    int fpscr;
  };

  offsetof(struct s, fpr[32][0])

the offsetof macro is specified to expand such that given

  static struct s t;

the following evaluates to an integer constant:

  &(t.fpr[32][0])

Since the t.fpr array has only 32 elements, a reference to t.fpr[32][0] is out
of bounds and thus undefined (there is no array fpr[32] and so no element 0 of
such an array).  As a result, the full expression does not yield a valid
integer constant as required and a diagnostic is justified.  With that I think
it's time to resolve this.

(Other questions were raised about offsetof in DR 496 but even those the
committee doesn't seem to be very interested in dealing with.)

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]