From d7291b3d09dba08faf2c4a6e332f012fbed8322f Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Thu, 5 Feb 2026 12:45:23 +0100 Subject: [PATCH 1/2] C flags: enable -Wswitch-enum on both GCC and Clang MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit `default` keyword silences "warning: enumeration value ‘FOO’ not handled in switch", making some bugs hard to spot. This caused issue #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 --- src/libAtomVM/CMakeLists.txt | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/libAtomVM/CMakeLists.txt b/src/libAtomVM/CMakeLists.txt index 0aa1eba95f..60731eff0a 100644 --- a/src/libAtomVM/CMakeLists.txt +++ b/src/libAtomVM/CMakeLists.txt @@ -132,9 +132,9 @@ add_library(libAtomVM ${SOURCE_FILES} ${HEADER_FILES}) target_include_directories(libAtomVM PUBLIC ${CMAKE_CURRENT_SOURCE_DIR}) target_compile_features(libAtomVM PUBLIC c_std_11) if (CMAKE_C_COMPILER_ID STREQUAL "GNU") - target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types) + target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} ${MAYBE_WERROR_FLAG} -Wextra -ggdb -Werror=incompatible-pointer-types -Wswitch-enum) elseif (CMAKE_C_COMPILER_ID MATCHES "Clang") - target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} -Wno-gnu-zero-variadic-macro-arguments --extra-warnings -Werror=incompatible-pointer-types ${MAYBE_WERROR_FLAG} -g) + target_compile_options(libAtomVM PUBLIC -Wall ${MAYBE_PEDANTIC_FLAG} -Wno-gnu-zero-variadic-macro-arguments --extra-warnings -Werror=incompatible-pointer-types -Wswitch-enum ${MAYBE_WERROR_FLAG} -g) endif() if (ENABLE_REALLOC_GC) From 112c2ff31811187a58d380fefeb8eb3040f4294e Mon Sep 17 00:00:00 2001 From: Davide Bettio Date: Thu, 5 Feb 2026 12:59:43 +0100 Subject: [PATCH 2/2] term.c: fix enumeration value not handled in switch warning Those missing cases were legit, still not obvious and they were causing a warning now. Signed-off-by: Davide Bettio --- src/libAtomVM/term.c | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/src/libAtomVM/term.c b/src/libAtomVM/term.c index 4b55b1df54..9fc3d29645 100644 --- a/src/libAtomVM/term.c +++ b/src/libAtomVM/term.c @@ -1024,6 +1024,11 @@ TermCompareResult term_compare(term t, term other, TermCompareOpts opts, GlobalC break; } } + case TERM_TYPE_INDEX_NIL: + // This cannot happen, since this branch is executed only when + // `type_t == type_other`, + // but we do `t == other` as the first thing, making this case unreachable. + case TERM_TYPE_INDEX_INVALID: default: UNREACHABLE(); }