[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <29259fbf-ee4c-764e-8158-274bb3914b9f@kernel.org>
Date: Tue, 1 Nov 2022 06:58:05 +0100
From: Jiri Slaby <jirislaby@...nel.org>
To: "Jason A. Donenfeld" <Jason@...c4.com>
Cc: linux-kernel@...r.kernel.org, Martin Liska <mliska@...e.cz>,
"David S. Miller" <davem@...emloft.net>,
Eric Dumazet <edumazet@...gle.com>,
Jakub Kicinski <kuba@...nel.org>,
Paolo Abeni <pabeni@...hat.com>, wireguard@...ts.zx2c4.com,
netdev@...r.kernel.org
Subject: Re: [PATCH] wireguard (gcc13): cast enum limits members to int in
prints
Hi,
On 31. 10. 22, 14:07, Jason A. Donenfeld wrote:
> On Mon, Oct 31, 2022 at 12:44:24PM +0100, Jiri Slaby (SUSE) wrote:
>> Since gcc13, each member of an enum has the same type as the enum [1]. And
>> that is inherited from its members. Provided "REKEY_AFTER_MESSAGES = 1ULL
>> << 60", the named type is unsigned long.
>>
>> This generates warnings with gcc-13:
>> error: format '%d' expects argument of type 'int', but argument 6 has type 'long unsigned int'
>>
>> Cast the enum members to int when printing them.
>>
>> Alternatively, we can cast it to ulong (to silence gcc < 12) and use %lu.
>> Alternatively, we can move REKEY_AFTER_MESSAGES away from the enum.
>>
>> [1] https://gcc.gnu.org/bugzilla/show_bug.cgi?id=36113
>
> Huh, interesting situation. It's interesting that 1<<60 even works at
> all on old gccs. I guess that in this case, it just takes the type of
> the actual constant, rather than of the enum type?
Exactly, on gcc <= 12, every enum member has a type depending solely on
its value. And yes, using anything outside <INT_MIN, INT_MAX> is
undefined (but obviously works). As well as using anything else than
_constants_.
thanks,
--
js
suse labs
Powered by blists - more mailing lists