From owner-sc22wg14+sc22wg14-domo2=www.open-std.org@open-std.org  Sat Dec 13 01:37:20 2025
Return-Path: <owner-sc22wg14+sc22wg14-domo2=www.open-std.org@open-std.org>
X-Original-To: sc22wg14-domo2
Delivered-To: sc22wg14-domo2@www.open-std.org
Received: by www.open-std.org (Postfix, from userid 521)
	id 1AF99356D33; Sat, 13 Dec 2025 01:37:20 +0100 (CET)
Delivered-To: sc22wg14@open-std.org
Received: from mail-ej1-f42.google.com (mail-ej1-f42.google.com [209.85.218.42])
	by www.open-std.org (Postfix) with ESMTP id B9DAF356A26
	for <sc22wg14@open-std.org>; Sat, 13 Dec 2025 01:37:19 +0100 (CET)
Received: by mail-ej1-f42.google.com with SMTP id a640c23a62f3a-b7633027cb2so293351866b.1
        for <sc22wg14@open-std.org>; Fri, 12 Dec 2025 16:37:19 -0800 (PST)
DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=gmail.com; s=20230601; t=1765586238; x=1766191038; darn=open-std.org;
        h=to:subject:message-id:date:from:mime-version:from:to:cc:subject
         :date:message-id:reply-to;
        bh=RdA3gi4b1KSmMwVvtLQDRTDaEp412Hp0zunB8RGbwaw=;
        b=dN5pv1FCKIWitlZakYz0i3x99223Bbo4VLpHbxuK6cQJB9nCCpsH35308wx+QQJnzH
         0nEyecEdjV/Z0ojkue4H4G6K6XRf+VfEvnZhkAb2rygweyh/AA1UdkWUrpcZV/XlP1ON
         dB5BfBl8PYgJ6MKsWuGrv/2XpAflvnOuR922KIqZlql3UsWaQOcbqlpoz1Z396DMrnZV
         t6n/7UNAJ0nInvpUlNz7N8qeZYN55pMmQAGqcKgQBX43kaIj8n2CZrEk9/BVn9BKxpEm
         TVVwFdFmrKCYbobu8/rIP248e/MM7yKL3jPOT0KHQvmOqWYT37UUz8HQpbQX/93DNPQX
         kKpQ==
X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed;
        d=1e100.net; s=20230601; t=1765586238; x=1766191038;
        h=to:subject:message-id:date:from:mime-version:x-gm-gg
         :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to;
        bh=RdA3gi4b1KSmMwVvtLQDRTDaEp412Hp0zunB8RGbwaw=;
        b=guQS4wNoIGjGrjjlNcgVbeLw/3tLwet3ShdsUUjCSiEOOOTvUaPtbI8SSs9ZkECOva
         Sn1EdaCm2NFJRGzhY3r+aG/AoM68c0WZtBQ5lMDXSrXtgOmuIVAfPhcNTYkvt/yZ1r2o
         I41oh9jnh5rT/Jc+6WvGimsHk8VtdZGrVSHSbD3J0iXFwEp/C2Fh3LfcPp1n4iHZLKd8
         12ZdQhYXo1iM9WjBcUyFTYXXn6SezsfBeWFkVcszBHiuikeoKqYWYK1/VZfS8aY7lqOp
         hMX3rCAJp/xgJeAC0YCPXLzruUq+isj6BjdEclabFe/zOTWPSJhuprnGr18ArOJvWotb
         QgJA==
X-Gm-Message-State: AOJu0YwUBfFVbFNuH7XwXd5nJ5yKD80D/iVxwBueKWrOkbsnam4lG5Wt
	9kCVVUkK3na61RDKB6kt1+G92zbKHhIOf2p/IltTvks8JMdKNPOpOggeeD2fpb/C3AIlhdpAmR3
	pPttBMSZRYzKjXsh/NGPVWIB4S1FIZrMrwG9G
X-Gm-Gg: AY/fxX7DqxGsgo+hccpmk17rPHRQtyyQnEY5zv96UbdUgYMMbLaQJyfZL5tf0YzxbT5
	LgXLiM1ILem/7lPW+Jn9MNe5fLAK4eneKlK/kW4qjUc5wx3IhEJfqnfz7z61QtrYWGXzbULGaNZ
	urkoEMzxBVqvKslcQR0ja2WBqmB6KkKmLxien39zYrKl1F1/dYKdQ0KBi37daos3bKgFNUU1CER
	we0dPO7oqfXni2P6MN2ntdMUwDQKH2p+YIXyJN4p9xIl/jQdB4uLpZ+wLEJd62unOuSHg==
X-Google-Smtp-Source: AGHT+IGlsSiPuetMsw6VCgQ2qsGXe/+ngww9LUtSRDfaB7ZCjFpFHntzDwiXy56nRsrbbUzT81uQu/QgM+8dzBFk6yE=
X-Received: by 2002:a17:906:4fd5:b0:b76:2667:7717 with SMTP id
 a640c23a62f3a-b7d23aa4046mr432110866b.56.1765586237908; Fri, 12 Dec 2025
 16:37:17 -0800 (PST)
MIME-Version: 1.0
From: Hubert Tong <hubert.reinterpretcast@gmail.com>
Date: Fri, 12 Dec 2025 19:36:50 -0500
X-Gm-Features: AQt7F2o1_9-oQfdUnw6nkn01ddITniiC7kXSMKF-0XjnUeCyW-qasButTS82Spk
Message-ID: <CACvkUqZydkjQGprRh3zcvM6MFNGNU4=52=mAxdvFSR0ST+aP8A@mail.gmail.com>
Subject: Integer promotions for enumerations: does not match Clang/GCC or
 (separately) C++
To: ISO C <sc22wg14@open-std.org>
Content-Type: multipart/alternative; boundary="00000000000087eb440645ca94fa"
Sender: owner-sc22wg14@open-std.org
Precedence: bulk

--00000000000087eb440645ca94fa
Content-Type: text/plain; charset="UTF-8"

Hi WG 14,

The resolution for FR-030 in WG 14 N3148 clarifies that, in the usual
arithmetic conversions, C23 converts values of an enumeration type to the
underlying type of the enumeration type. This is added immediately before
"integer promotions are performed on both operands".

I think the change should have been made instead to the integer
promotions, which have two issues:

   - They rely on the unclear "values of the original type" (i.e., the
   values of the enumerated type), which can be interpreted as the set
   comprising the values of the enumeration constants. Under such an
   interpretation, the enumerated type `typedef enum { E0 } E;` portably
   promotes to `int` (which is what happens in C++); however, for C, Clang and
   GCC promote to the promoted underlying type (which could be `unsigned`).

   https://godbolt.org/z/TW5vbjcbb:
   typedef enum { E0 } E;
   static_assert((+(E)E0 - 1 < 0) == (E0 - 1 < 0), "Must pass for C++");

   - Values of enumerated type with rank greater than that of `int` are not
   promoted (but both Clang and GCC act in a manner consistent with such
   promotion occuring: https://godbolt.org/z/s61oxKj3z). I am not entirely
   sure how to observe the promotion without relying on the text of
   diagnostics though.

So either to better align with the existing C implementation behaviour of
Clang and GCC or to align with the behaviour of C++, I think that the
integer promotions should be changed and the usual arithmetic conversions
should apply the integer promotions directly to operands of enumerated type.

Thanks,


Hubert Tong

--00000000000087eb440645ca94fa
Content-Type: text/html; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable

<div dir=3D"ltr"><div>Hi WG 14,</div><div><br></div><div>The resolution for=
 FR-030 in WG 14 N3148 clarifies that, in the usual=20
arithmetic conversions, C23 converts values of an enumeration type to=20
the underlying type of the enumeration type. This is added immediately befo=
re &quot;integer promotions are performed on both operands&quot;.</div><div=
><br></div><div>I think the change should have been made instead to the int=
eger promotions,=C2=A0which have two issues:</div><ul><li>They rely on the =
unclear &quot;values of the original type&quot; (i.e., the values of the en=
umerated type), which can be interpreted as the set comprising the values o=
f the enumeration constants. Under such an interpretation, the enumerated t=
ype `typedef enum { E0 } E;` portably promotes to `int` (which is what happ=
ens in C++); however, for C, Clang and GCC promote=C2=A0to the promoted und=
erlying type (which could be `unsigned`).<br><br><a href=3D"https://godbolt=
.org/z/TW5vbjcbb">https://godbolt.org/z/TW5vbjcbb</a>:<br><span style=3D"fo=
nt-family:monospace">typedef enum { E0 } E;<br>static_assert((+(E)E0 - 1 &l=
t; 0) =3D=3D (E0 - 1 &lt; 0), &quot;Must pass for C++&quot;);</span><br><br=
></li><li>Values of enumerated type with rank greater than that of `int` ar=
e not promoted (but both Clang and GCC act in a manner consistent with such=
 promotion occuring:=C2=A0<a href=3D"https://godbolt.org/z/s61oxKj3z">https=
://godbolt.org/z/s61oxKj3z</a>). I am not entirely sure how to observe the =
promotion without relying on the text of diagnostics though.</li></ul><div>=
So either to better align with the existing C implementation behaviour of C=
lang and GCC or to align with the behaviour of C++, I think that the intege=
r promotions should be changed and the usual arithmetic conversions should =
apply the integer promotions directly to operands of enumerated type.</div>=
<div><br></div><div>Thanks,</div><div><br></div><div><br></div><div>Hubert =
Tong</div></div>

--00000000000087eb440645ca94fa--
