[Date Prev][Date Next][Thread Prev][Thread Next]
[Date Index]
[Thread Index]
- Subject: Re: C++20 deprecation warning regarding enum arithmetic
- From: "Pierre Chapuis" <lua@...>
- Date: Wed, 22 Mar 2023 16:42:19 +0100
The value added is always TM_ADD, It's just a shift trick to find the metatable ID corresponding to a binary operation code.
If adding an integer works, it would be enough to do something like `#define TM_ADD_OFFSET ((int)TM_ADD)` and use this instead.
--
Pierre Chapuis
On Wed, Mar 22, 2023, at 16:12, Mouse wrote:
>> [...adding enums of different types...g++ warning...]
>> While you may of course cast one of the enum values to int before doing the $
>
> I would much prefer the cast. The semantics are the same (or at least
> very close to) and IMO the cast makes it significantly clearer to the
> reader what's going on.
>
> However, I would also argue that using enums as "just funny ints",
> which semi-must be going on for adding enums from different
> enumerations to make any semantic sense at all, is a Very Bad Idea,
> even in C. IMO manifest constants whose actual values are important
> should be #defines, not enum members. (If there's a real need for
> value-important int-ish manifest constants with the scoping properties
> of enum constants rather than of #defines, I would say the right thing
> is to create a new kind of manifest constant, not to abuse enums.)
>
>> I wouldn't call it a bug, but [...]
>
> I would (would call it a bug, that is), but currently at just the
> semantic level.
>
> But what you or I think of it doesn't matter nearly as much as what the
> Lua people think of it.
>
> /~\ The ASCII Mouse
> \ / Ribbon Campaign
> X Against HTML mouse@rodents-montreal.org
> / \ Email! 7D C8 61 52 5D E7 2D 39 4E F1 31 3E E8 B3 27 4B