refactor: Use more scoped enums - #7086
Conversation
|
This PR has conflicts, please resolve them in order for the PR to be reviewed. |
…into refactor/scoped-enums
|
All conflicts have been resolved. Assigned reviewers can now start or resume their review. |
bthomee
left a comment
There was a problem hiding this comment.
I went through all lines to the best of my ability, and only a few things stood out that are mostly unrelated to this PR.
For good measure I used Claude to also perform a scan and it reported that the changed enums etc. were safe and resulted in identical behavior. It also noticed the changes to Beast severities as a breaking API change, but in our case this is fine to ignore.
| // object. Intended for STNumber. | ||
| SMdDefault = SMdChangeOrig | SMdChangeNew | SMdDeleteFinal | SMdCreate | ||
| }; | ||
| static constexpr auto kSMD_NEVER = 0x00; |
There was a problem hiding this comment.
Is having these as constexpr better than as enum class members?
There was a problem hiding this comment.
The intention of anonymous enum as used here is exactly to make constants. At the time of writing this was a good way but i believe in modern c++ there are better ways, like static constexpr auto for example :)
| DisableApiPriorV2 = 0b0000'0010, | ||
|
|
||
| // IMPORTANT `All` must be union of all of the above; see also operator~ | ||
| All = 0b0000'0011 |
There was a problem hiding this comment.
FWIW setting this to All = IncludeDate | DisableApiPriorV2 would be more elegant, and also consistent with how a similar value was set in SField.h.
It's probably outside the scope of this PR though, but at the same time not something anyone would create a dedicated PR for...
There was a problem hiding this comment.
I can try to apply that here
| // MaxPacketSize = 484 | ||
| MaxPacketSize = 1472 | ||
| }; | ||
| // MaxPacketSize = 484 |
There was a problem hiding this comment.
Deleted. i only left it before as it already was the "old value" that was left in a comment for some reason
| TokenMemberSeparator, | ||
| TokenComment, | ||
| TokenError | ||
| enum class TokenType { |
There was a problem hiding this comment.
Could you make all enums where it's possible to be uint8_t?
There was a problem hiding this comment.
Sounds like an unrelated and slightly dangerous change
| break; | ||
|
|
||
| case UintValue: | ||
| case ValueType::Uint: |
There was a problem hiding this comment.
| case ValueType::Uint: | |
| case ValueType::UInt: |
While it's not too late (uint is weird for me though - I like uint or UInt)
There was a problem hiding this comment.
Let's just fix all Uint in the project while we are here :)
| static constexpr auto kSMD_ALWAYS = 0x10; // value when node containing it is affected at all | ||
| static constexpr auto kSMD_BASE_TEN = 0x20; // value is treated as base 10, overriding behavior |
There was a problem hiding this comment.
Can't align them differently unless we want to clang-format: off
| // Bitwise flags, 86 files | ||
| // Bitwise flags, 86 files, used in macros files | ||
| // NOLINTNEXTLINE(cppcoreguidelines-use-enum-class) | ||
| enum Privilege { |
There was a problem hiding this comment.
Can't we make this an enum class?
If there are other enums left, please, take a look as well
There was a problem hiding this comment.
No and it even says why it was not converted. It would break macros files and i don't want to deal with external scripts in this PR so leaving this for future.
| switch (value.type()) | ||
| { | ||
| case json::NullValue: { | ||
| case json::ValueType::Null: { |
There was a problem hiding this comment.
We're in json namespace, so we can probably remove json:: prefix here
High Level Overview of Change
This PR converts more C enums to modern scoped enums.
Remaining enums with NOLINT are best left alone for now. Comments above their respective NOLINT indicate why.
API Impact
No impact.