On Sat, Jan 14, 2023 at 4:17 PM Bruno Haible <br...@clisp.org> wrote: > > Khem Raj wrote: > > [2] https://reviews.llvm.org/D133574 > > Thanks for the heads-up. > > > WG14 N2350 made very clear that it is an UB having type definitions > > within "offsetof" [1]. > > [1] https://www.open-std.org/jtc1/sc22/wg14/www/docs/n2350.htm > > This document is not normative; it is merely a discussion document. > > What's (quasi) normative is > > * n3047.pdf = C23, which says in 7.21.(3) > "If the specified type defines a new type or if the specified member is > a bit-field, the behavior is undefined." > > * n2176.pdf = C18, which in 7.19.(3) merely says > "If the specified member is a bit-field, the behavior is undefined." > > So, only C23 and higher require to avoid offsetof with a new type. > > Since gnulib/lib/stdalign.h mentions an _Alignof bug in older versions of > GCC and clang and some of these older versions (e.g. GCC 4.8.5) support C11, > it is better to enable the workaround only for C23 and higher, not for > C11 and higher. >
I think if its enabled only for c2x and newer, clang will still errors out for __STDC_VERSION__= 201710L I have sent out a patch which replicates the logic from gnulib/lib/stdalign.h.in which should address this as well. > > +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L && > > !defined(__cplusplus) > > The '!defined(__cplusplus)' part is redundant here. > right. Dropped in v2. > Bruno > > >