Stricter checks for enum definitions #12945
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
This PR makes it an error to reopen an enum with an explicit base type that is different from its original definition:
It also improves overflow detection so that it works immediately after an enum member with a value is declared: (previously the overflow error would trigger on the subsequent enum member afterwards, or not at all)
Note that the overflow criterion for signed flags enums is the same as normal multiplication. And indeed this is the case when the overflowing member is succeeded by a valueless member:
Some code in the wild might assume it is okay to have
Foo2::B == -0x80000000
here. IMO this is a bug rather than a breaking change.Finally,
visit_enum_member
's implementation is largely refactored, and there are fewer parameters and return values now. (It also removes one of the compiler's remaining non-forwarding uses of an**options
parameter.)