On 2023-01-14 16:17, Bruno Haible wrote:
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."

I'm afraid this wording in n3047 is unclear. Ordinarily one would look at n3047's section "Type definitions" to interpret the phrase "defines a new type", but as that section merely talks about typedefs it doesn't seem to be relevant here. I can't find any part of the standard that talks about "defining a new type".

All the standardizers wanted here is for the TYPE to not contain a top-level comma in 'offsetof (TYPE, MEMBER)' because that would screw up macro argument identification.

I hope Clang 16 is not reporting an error for 'offsetof (struct {char a; int b;}, b)'; if so, it's gone off the deep end. A nameless struct does not "define a new type" for some reasonable definitions of the term "define a new type", and since the standard doesn't define that term the Clang developers should be cautious about diagnostics in this messy area when a lot of code out there uses offsetof in precisely this way.

Reply via email to