[Bug c++/95942] [11 regression] offsetof on an array: error: 'e' is not a constant expression

jason at gcc dot gnu.org gcc-bugzilla@gcc.gnu.org
Thu Oct 15 16:45:52 GMT 2020


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

Jason Merrill <jason at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
         Resolution|---                         |INVALID
             Status|NEW                         |RESOLVED

--- Comment #5 from Jason Merrill <jason at gcc dot gnu.org> ---
C11 says,

....and
  offsetof(type, member-designator)
which expands to an integer constant expression that has type size_t, the value
of which is the offset in bytes, to the structure member (designated by
member-designator), from the beginning of its structure (designated by type).
The type and member designator shall be such that given
  static type t;
then the expression &(t.member-designator) evaluates to an address constant.
(If the specified member is a bit-field, the behavior is undefined.)

And __builtin_offsetof is only documented to be usable as an implementation of
the offsetof macro.

Since e is not constant, the expression above is not an address constant, so
the offsetof expression is ill-formed.  The change mentioned in comment #2
fixed this and various related issues with wrongly treating parameters as
sufficiently constant.


More information about the Gcc-bugs mailing list