This is the mail archive of the
gcc-bugs@gcc.gnu.org
mailing list for the GCC project.
[Bug c/67882] surprising offsetof result on an invalid array member without diagnostic
- From: "msebor at gcc dot gnu.org" <gcc-bugzilla at gcc dot gnu dot org>
- To: gcc-bugs at gcc dot gnu dot org
- Date: Thu, 19 Apr 2018 17:39:38 +0000
- Subject: [Bug c/67882] surprising offsetof result on an invalid array member without diagnostic
- Auto-submitted: auto-generated
- References: <bug-67882-4@http.gcc.gnu.org/bugzilla/>
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.)