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

Jakub Jelinek <jakub at gcc dot gnu.org> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
                 CC|                            |jakub at gcc dot gnu.org,
                   |                            |jason at gcc dot gnu.org

--- Comment #1 from Jakub Jelinek <jakub at gcc dot gnu.org> ---
struct S { int s[4]; };

int
foo (int x)
{
  return __builtin_offsetof (struct S, s[x]);
}
This is rejected since r11-557-gbeb019d346b903c16b9fd349937de444b6a8b6c0 in
C++, accepted in C.
This is I believe invalid in both C99 and C23 and C++ just inherits the C
definition and adds additional constraints to that:
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 subobject (designated by
member-designator), from the beginning of any object of type 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 type defines a new type or if the specified member is a
bit-field, the behavior is undefined.

Now &(t. s[x]) definitely doesn't evaluate to address constant and offsetof
(struct S, s[x]) doesn't yield integer constant, so this is definitely outside
of the standards, accepted in C and before in C++ as well as an extension.

Reply via email to