Enable -Wswitch-enum GCC and Clang flag#2087
Draft
bettio wants to merge 2 commits intoatomvm:mainfrom
Draft
Conversation
`default` keyword silences "warning: enumeration value ‘FOO’ not handled in switch", making some bugs hard to spot. This caused issue atomvm#2086: `term_compare()` wasn't handling funs due to an unnoticed missing case. However `default` is still useful for telling compiler than any other case is unreachable, but we don't want to silence warnings. So the right strategy is using `-Wswitch-enum`, while doing fall through to the default, for each enum value that we explicitly don't want to handle. Signed-off-by: Davide Bettio <davide@uninstall.it>
Those missing cases were legit, still not obvious and they were causing a warning now. Signed-off-by: Davide Bettio <davide@uninstall.it>
mat-hek
reviewed
Feb 6, 2026
| // `type_t == type_other`, | ||
| // but we do `t == other` as the first thing, making this case unreachable. | ||
| case TERM_TYPE_INDEX_INVALID: | ||
| default: |
Collaborator
Author
There was a problem hiding this comment.
default: UNREACHABLE(); tells the compiler that any other value is undefined behavior, so it can perform additional optimizations. Otherwise it stills emit code for handling values outside the cases we defined.
Variables having an enum type are glorified integers, so the compiler by default doesn't infer that only allowed values are the enum values.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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 will prevent bugs such as #2086.
These changes are made under both the "Apache 2.0" and the "GNU Lesser General
Public License 2.1 or later" license terms (dual license).
SPDX-License-Identifier: Apache-2.0 OR LGPL-2.1-or-later