[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [PATCH] Define alignof_slot using _Alignof when using C11 or newer
From: |
Bruno Haible |
Subject: |
Re: [PATCH] Define alignof_slot using _Alignof when using C11 or newer |
Date: |
Sun, 15 Jan 2023 01:17:10 +0100 |
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.
> +#elif defined(__STDC_VERSION__) && __STDC_VERSION__ >= 201112L &&
> !defined(__cplusplus)
The '!defined(__cplusplus)' part is redundant here.
Bruno