From 4b291ddf4bdd5c29c58ea153761ade7a9f4e1d92 Mon Sep 17 00:00:00 2001 From: Richard Barnes Date: Tue, 30 Jul 2024 12:26:04 -0700 Subject: [PATCH] Make fallthroughs explicit and enable warnings around this --- CMakeLists.txt | 4 ++-- core/desugarer.cpp | 2 +- core/vm.cpp | 2 +- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 213539449..84e554b6a 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -36,8 +36,8 @@ set(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${GLOBAL_OUTPUT_PATH}) if (${CMAKE_CXX_COMPILER_ID} MATCHES "Clang" OR ${CMAKE_CXX_COMPILER_ID} STREQUAL "GNU") set(OPT "-O3") - set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -pedantic -std=c99 -O3 ${OPT}") - set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Woverloaded-virtual -pedantic -std=c++17 -fPIC ${OPT}") + set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -Wextra -Wimplicit-fallthrough -pedantic -std=c99 -O3 ${OPT}") + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -g -Wall -Wextra -Wimplicit-fallthrough -Woverloaded-virtual -pedantic -std=c++17 -fPIC ${OPT}") else() # TODO: Windows support. message(FATAL_ERROR "Compiler ${CMAKE_CXX_COMPILER_ID} not supported") diff --git a/core/desugarer.cpp b/core/desugarer.cpp index 6c38eb913..611c1545e 100644 --- a/core/desugarer.cpp +++ b/core/desugarer.cpp @@ -732,7 +732,7 @@ class Desugarer { } break; case BOP_MANIFEST_UNEQUAL: invert = true; - /* fallthrough */ + [[fallthrough]]; case BOP_MANIFEST_EQUAL: { ast_ = equals(ast->location, ast->left, ast->right); if (invert) diff --git a/core/vm.cpp b/core/vm.cpp index 0e21c82aa..7cc0a8655 100644 --- a/core/vm.cpp +++ b/core/vm.cpp @@ -2390,7 +2390,7 @@ class Interpreter { stack.top().val2 = scratch; stack.top().kind = FRAME_BINARY_OP; } - // Falls through. + [[fallthrough]]; case FRAME_BINARY_OP: { const auto &ast = *static_cast(f.ast); const Value &lhs = stack.top().val;