bug-gnulib@gnu.org mirror (unofficial)
 help / color / mirror / Atom feed
From: Bruno Haible <bruno@clisp.org>
To: bug-gnulib@gnu.org, Khem Raj <raj.khem@gmail.com>
Subject: Re: [PATCH] Define alignof_slot using _Alignof when using C11 or newer
Date: Sun, 15 Jan 2023 01:17:10 +0100	[thread overview]
Message-ID: <4385269.dumfJixkPq@nimes> (raw)
In-Reply-To: <20230114232744.215167-1-raj.khem@gmail.com>

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





  reply	other threads:[~2023-01-15  0:17 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-01-14 23:27 [PATCH] Define alignof_slot using _Alignof when using C11 or newer Khem Raj
2023-01-15  0:17 ` Bruno Haible [this message]
2023-01-15  1:20   ` Khem Raj
2023-01-15  1:59   ` Paul Eggert

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://lists.gnu.org/mailman/listinfo/bug-gnulib

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=4385269.dumfJixkPq@nimes \
    --to=bruno@clisp.org \
    --cc=bug-gnulib@gnu.org \
    --cc=raj.khem@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).