lua-users home
lua-l archive

[Date Prev][Date Next][Thread Prev][Thread Next] [Date Index] [Thread Index]


Hi Lua crew,

I found that when building Lua 5.4.4 as C++20 source using gcc 12, there are warnings like this:

lcode.c:1446:29: warning: arithmetic between different enumeration types 'BinOpr' and 'TMS' is deprecated [-Wdeprecated-enum-enum-conversion]

While it is of course possible to silence the warning with the appropriate command line switch, it would be preferable to avoid the warning in the first place.

The warning tells you that you shouldn't do arithmetic involving different enum types, because this may become an error in a future version of the C++ standard. The C++ folks want to reduce the possibility of accidental errors, and would like you to make type conversions explicit in such cases.

While you may of course cast one of the enum values to int before doing the arithmetic, this is a bit verbose IMHO. A fairly unobtrusive, while perhaps somewhat obscure, way to avoid the warning is to use an unary + with one of the enum operands to cause an implicit conversion to int.

There are several places in lcode.c where this occurs, where values from two different enum types are added. I didn't notice it elsewhere.

I wouldn't call it a bug, but further down the road, it may turn into one, when new C++ standard versions come out.

Cheers

Stefan