[Development] API style guide: scoped enum or not?

Giuseppe D'Angelo giuseppe.dangelo at kdab.com
Thu Jul 6 15:07:15 CEST 2023


Il 14/06/23 14:59, Marc Mutz via Development ha scritto:
> A) new enums MUST have an explicit underlying type¹²
> 
> For unscoped enums, the compiler otherwise picks one, possibly resulting
> in BiC when new addtions change the underlying type or otherwise just
> warnings because one compiler uses a signed and the other an unsigned
> type (most recent exmaple: QTBUG-113792). For scoped enums, the type is
> int, but probably not always, and why require the reader of the code to
> know the C++ rules when we can make it explicit?

By the way, the last sentence is not entirely correct. For scoped enums 
that don't specify otherwise, the underlying type is int, always. File 
under another advantage of using "enum class". Explicitly stating the 
underlying type for enum classes makes me actually wonder that there 
might be something tricky going on (e.g. the enum is being shoved into a 
bitfield or so). I'd rather just see "by default" `enum class Foo {`.

My 2 c,
-- 
Giuseppe D'Angelo | giuseppe.dangelo at kdab.com | Senior Software Engineer
KDAB (France) S.A.S., a KDAB Group company
Tel. France +33 (0)4 90 84 08 53, http://www.kdab.com
KDAB - The Qt, C++ and OpenGL Experts

-------------- next part --------------
A non-text attachment was scrubbed...
Name: smime.p7s
Type: application/pkcs7-signature
Size: 4244 bytes
Desc: Firma crittografica S/MIME
URL: <http://lists.qt-project.org/pipermail/development/attachments/20230706/9d3fde91/attachment.bin>


More information about the Development mailing list