]> git.ipfire.org Git - thirdparty/dbus.git/commit
internals: Use Standard C offsetof macro if available
authorSimon McVittie <smcv@collabora.com>
Fri, 10 Dec 2021 15:12:59 +0000 (15:12 +0000)
committerSimon McVittie <smcv@collabora.com>
Mon, 13 Dec 2021 12:36:35 +0000 (12:36 +0000)
commita24cf746e2a8191070efd1300a15d37284aaf2fa
tree9dbff6f55b0072b238dca974de65aa85546474bd
parent83232393ef8a39400223663f978746f9d27c49be
internals: Use Standard C offsetof macro if available

clang 13 fails to compile our current implementation with:

.../dbus/dbus-message.c:2070:3: error: variable length array folded to constant array as an extension [-Werror,-Wgnu-folding-constant]
  _DBUS_STATIC_ASSERT (_DBUS_ALIGNOF (DBusMessageRealIter) <=
  ^
.../dbus/dbus-internals.h:460:25: note: expanded from macro '_DBUS_STATIC_ASSERT'
  typedef struct { char _assertion[(expr) ? 1 : -1]; } \

This appears to be because the "traditional" definition of
offsetof(), which we're hard-coding here, does not qualify as a constant
expression under C rules due to its use of pointer casts.

Modern compilers like gcc and clang have a built-in implementation
of offsetof that *is* a constant expression.

Signed-off-by: Simon McVittie <smcv@collabora.com>
dbus/dbus-internals.h