From 5e6d144567d31ec778ed5d4fb5d4c99f36973f16 Mon Sep 17 00:00:00 2001 From: Desour Date: Mon, 12 Jun 2023 22:23:32 +0200 Subject: [PATCH] Enable -Wimplicit-fallthrough and use [[fallthrough]] attribute --- src/CMakeLists.txt | 2 +- src/client/hud.cpp | 1 + src/rollback_interface.cpp | 2 ++ src/script/common/c_content.cpp | 1 + src/util/numeric.cpp | 12 ++++++------ 5 files changed, 11 insertions(+), 7 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 91eae9792..3f14e8ec0 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -761,7 +761,7 @@ if(MSVC) else() # GCC or compatible compilers such as Clang set(WARNING_FLAGS "-Wall -Wextra") - set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-parameter -Wno-implicit-fallthrough") + set(WARNING_FLAGS "${WARNING_FLAGS} -Wno-unused-parameter") if(WARN_ALL) set(RELEASE_WARNING_FLAGS "${WARNING_FLAGS}") else() diff --git a/src/client/hud.cpp b/src/client/hud.cpp index b18bd5382..9ad5ef5e9 100644 --- a/src/client/hud.cpp +++ b/src/client/hud.cpp @@ -440,6 +440,7 @@ void Hud::drawLuaElements(const v3s16 &camera_offset) case HUD_ELEM_IMAGE_WAYPOINT: { if (!calculateScreenPos(camera_offset, e, &pos)) break; + [[fallthrough]]; } case HUD_ELEM_IMAGE: { video::ITexture *texture = tsrc->getTexture(e->text); diff --git a/src/rollback_interface.cpp b/src/rollback_interface.cpp index 6f19f441d..a5a63076f 100644 --- a/src/rollback_interface.cpp +++ b/src/rollback_interface.cpp @@ -65,6 +65,7 @@ std::string RollbackAction::toString() const os << ", " << itos(n_new.param2); os << ", " << serializeJsonString(n_new.meta); os << ')'; + break; case TYPE_MODIFY_INVENTORY_STACK: os << "modify_inventory_stack ("; os << serializeJsonString(inventory_location); @@ -73,6 +74,7 @@ std::string RollbackAction::toString() const os << ", " << (inventory_add ? "add" : "remove"); os << ", " << serializeJsonString(inventory_stack.getItemString()); os << ')'; + break; default: return ""; } diff --git a/src/script/common/c_content.cpp b/src/script/common/c_content.cpp index 9a9132c09..299975100 100644 --- a/src/script/common/c_content.cpp +++ b/src/script/common/c_content.cpp @@ -478,6 +478,7 @@ TileDef read_tiledef(lua_State *L, int index, u8 drawtype, bool special) // "break" is omitted here intentionaly, as PLANTLIKE // FIRELIKE drawtype both should default to having // backface_culling to false. + [[fallthrough]]; case NDT_MESH: case NDT_LIQUID: default_culling = false; diff --git a/src/util/numeric.cpp b/src/util/numeric.cpp index 3bcac5335..423049a37 100644 --- a/src/util/numeric.cpp +++ b/src/util/numeric.cpp @@ -90,12 +90,12 @@ u64 murmur_hash_64_ua(const void *key, int len, unsigned int seed) const unsigned char *data2 = (const unsigned char *)data; switch (len & 7) { - case 7: h ^= (u64)data2[6] << 48; - case 6: h ^= (u64)data2[5] << 40; - case 5: h ^= (u64)data2[4] << 32; - case 4: h ^= (u64)data2[3] << 24; - case 3: h ^= (u64)data2[2] << 16; - case 2: h ^= (u64)data2[1] << 8; + case 7: h ^= (u64)data2[6] << 48; [[fallthrough]]; + case 6: h ^= (u64)data2[5] << 40; [[fallthrough]]; + case 5: h ^= (u64)data2[4] << 32; [[fallthrough]]; + case 4: h ^= (u64)data2[3] << 24; [[fallthrough]]; + case 3: h ^= (u64)data2[2] << 16; [[fallthrough]]; + case 2: h ^= (u64)data2[1] << 8; [[fallthrough]]; case 1: h ^= (u64)data2[0]; h *= m; }