diff --git a/docs/CODING_STYLE.md b/docs/CODING_STYLE.md index 0604bf24b..bf89e058b 100644 --- a/docs/CODING_STYLE.md +++ b/docs/CODING_STYLE.md @@ -148,5 +148,6 @@ We are using C++17 standard. You can safely use: * Use `static constexpr T v = ...;` * You can use ``, ``, ``, and `` * Prefer `using T = ...;` instead of `typedef ... T` +* Use `[[fallthrough]]` if needed * We use gcc 9.2 or clang 9.0 on Linux, so check the features available in https://en.cppreference.com/w/cpp/compiler_support diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 321f7b91d..c6c024b58 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,5 @@ # Aseprite -# Copyright (C) 2019-2020 Igara Studio S.A. +# Copyright (C) 2019-2022 Igara Studio S.A. # Copyright (C) 2001-2018 David Capello ###################################################################### @@ -8,6 +8,9 @@ if(UNIX) # All warnings except for switch cases with missing enum items set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wall -Wno-switch") + + # Prefer C++17 [[fallthrough]] attribute + set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -Wimplicit-fallthrough") endif() if(MSVC) diff --git a/src/app/commands/cmd_undo_history.cpp b/src/app/commands/cmd_undo_history.cpp index 75657f76e..24e5bd404 100644 --- a/src/app/commands/cmd_undo_history.cpp +++ b/src/app/commands/cmd_undo_history.cpp @@ -110,6 +110,7 @@ public: case ui::kMouseDownMessage: captureMouse(); + [[fallthrough]]; case ui::kMouseMoveMessage: if (hasCapture()) { diff --git a/src/app/commands/filters/color_curve_editor.cpp b/src/app/commands/filters/color_curve_editor.cpp index 135d619fe..270c6c871 100644 --- a/src/app/commands/filters/color_curve_editor.cpp +++ b/src/app/commands/filters/color_curve_editor.cpp @@ -120,7 +120,8 @@ bool ColorCurveEditor::onProcessMessage(Message* msg) captureMouse(); - // continue in motion message... + // Continue in motion message... + [[fallthrough]]; } case kMouseMoveMessage: { diff --git a/src/app/file/png_format.cpp b/src/app/file/png_format.cpp index 60e2f06f0..923d09a26 100644 --- a/src/app/file/png_format.cpp +++ b/src/app/file/png_format.cpp @@ -255,12 +255,14 @@ bool PngFormat::onLoad(FileOp* fop) case PNG_COLOR_TYPE_RGB_ALPHA: fop->sequenceSetHasAlpha(true); + [[fallthrough]]; case PNG_COLOR_TYPE_RGB: pixelFormat = IMAGE_RGB; break; case PNG_COLOR_TYPE_GRAY_ALPHA: fop->sequenceSetHasAlpha(true); + [[fallthrough]]; case PNG_COLOR_TYPE_GRAY: pixelFormat = IMAGE_GRAYSCALE; break; @@ -799,6 +801,7 @@ void PngFormat::saveColorSpace(png_structp png_ptr, png_infop info_ptr, } // Continue to RGB case... + [[fallthrough]]; case gfx::ColorSpace::RGB: { if (colorSpace->hasPrimaries()) { diff --git a/src/app/ui/browser_view.cpp b/src/app/ui/browser_view.cpp index d8931ba78..827608fdd 100644 --- a/src/app/ui/browser_view.cpp +++ b/src/app/ui/browser_view.cpp @@ -417,6 +417,7 @@ private: inImage = true; else if (ev_type == CMARK_EVENT_EXIT) inImage = false; + break; } case CMARK_NODE_LINK: { @@ -434,6 +435,7 @@ private: } inLink = nullptr; } + break; } } diff --git a/src/app/ui/color_selector.cpp b/src/app/ui/color_selector.cpp index 58c263f47..dba11976c 100644 --- a/src/app/ui/color_selector.cpp +++ b/src/app/ui/color_selector.cpp @@ -316,8 +316,7 @@ bool ColorSelector::onProcessMessage(ui::Message* msg) break; captureMouse(); - - // Continue... + [[fallthrough]]; case kMouseMoveMessage: { MouseMessage* mouseMsg = static_cast(msg); diff --git a/src/app/ui/file_list.cpp b/src/app/ui/file_list.cpp index 3e4f85d46..e220ec31b 100644 --- a/src/app/ui/file_list.cpp +++ b/src/app/ui/file_list.cpp @@ -178,6 +178,7 @@ bool FileList::onProcessMessage(Message* msg) case kMouseDownMessage: captureMouse(); + [[fallthrough]]; case kMouseMoveMessage: if (hasCapture()) { diff --git a/src/app/ui/palette_view.cpp b/src/app/ui/palette_view.cpp index f7718a39c..d60fee43f 100644 --- a/src/app/ui/palette_view.cpp +++ b/src/app/ui/palette_view.cpp @@ -339,8 +339,7 @@ bool PaletteView::onProcessMessage(Message* msg) } captureMouse(); - - // Continue... + [[fallthrough]]; case kMouseMoveMessage: { MouseMessage* mouseMsg = static_cast(msg); diff --git a/src/app/ui/toolbar.cpp b/src/app/ui/toolbar.cpp index 912499696..171d3e8c7 100644 --- a/src/app/ui/toolbar.cpp +++ b/src/app/ui/toolbar.cpp @@ -245,7 +245,7 @@ bool ToolBar::onProcessMessage(Message* msg) m_openedRecently = false; releaseMouse(); - // fallthrough + [[fallthrough]]; case kMouseLeaveMessage: if (hasCapture()) @@ -609,7 +609,7 @@ bool ToolBar::ToolStrip::onProcessMessage(Message* msg) case kMouseDownMessage: captureMouse(); - // fallthrough + [[fallthrough]]; case kMouseMoveMessage: { MouseMessage* mouseMsg = static_cast(msg); diff --git a/src/doc/handle_anidir.cpp b/src/doc/handle_anidir.cpp index 6ccf383a9..a8c37fbad 100644 --- a/src/doc/handle_anidir.cpp +++ b/src/doc/handle_anidir.cpp @@ -50,6 +50,7 @@ frame_t calculate_next_frame( case AniDir::REVERSE: frameDelta = -frameDelta; + [[fallthrough]]; case AniDir::FORWARD: frame += frameDelta; diff --git a/src/ui/entry.cpp b/src/ui/entry.cpp index dccf2bb99..f0ff77e92 100644 --- a/src/ui/entry.cpp +++ b/src/ui/entry.cpp @@ -395,6 +395,8 @@ bool Entry::onProcessMessage(Message* msg) if (!m_selecting_words.isEmpty()) m_selecting_words.reset(); + [[fallthrough]]; + case kMouseMoveMessage: if (hasCapture()) { bool is_dirty = false; diff --git a/src/ui/listbox.cpp b/src/ui/listbox.cpp index 1ba6ba848..6f4ba79d4 100644 --- a/src/ui/listbox.cpp +++ b/src/ui/listbox.cpp @@ -206,6 +206,7 @@ bool ListBox::onProcessMessage(Message* msg) case kMouseDownMessage: captureMouse(); + [[fallthrough]]; case kMouseMoveMessage: if (hasCapture()) { diff --git a/src/ui/manager.cpp b/src/ui/manager.cpp index 774dd1940..32b05cd6d 100644 --- a/src/ui/manager.cpp +++ b/src/ui/manager.cpp @@ -1858,11 +1858,10 @@ bool Manager::processFocusMovementMessage(Message* msg) break; // Arrow keys - case kKeyLeft: if (!cmp) cmp = cmp_left; - case kKeyRight: if (!cmp) cmp = cmp_right; - case kKeyUp: if (!cmp) cmp = cmp_up; + case kKeyLeft: if (!cmp) cmp = cmp_left; [[fallthrough]]; + case kKeyRight: if (!cmp) cmp = cmp_right; [[fallthrough]]; + case kKeyUp: if (!cmp) cmp = cmp_up; [[fallthrough]]; case kKeyDown: if (!cmp) cmp = cmp_down; - // More than one widget if (count > 1) { // Position where the focus come diff --git a/src/ui/menu.cpp b/src/ui/menu.cpp index 3b6f07594..14412a199 100644 --- a/src/ui/menu.cpp +++ b/src/ui/menu.cpp @@ -443,7 +443,7 @@ bool MenuBox::onProcessMessage(Message* msg) if (!base->was_clicked) break; - //[[fallthrough]]; + [[fallthrough]]; } case kMouseDownMessage: diff --git a/src/ui/scroll_bar.cpp b/src/ui/scroll_bar.cpp index f86be28d8..4a2d88236 100644 --- a/src/ui/scroll_bar.cpp +++ b/src/ui/scroll_bar.cpp @@ -132,7 +132,8 @@ bool ScrollBar::onProcessMessage(Message* msg) setSelected(true); captureMouse(); - // continue to kMouseMoveMessage handler... + // Continue to kMouseMoveMessage handler... + [[fallthrough]]; } case kMouseMoveMessage: diff --git a/src/ui/slider.cpp b/src/ui/slider.cpp index cf4c44233..39d72ae3e 100644 --- a/src/ui/slider.cpp +++ b/src/ui/slider.cpp @@ -115,7 +115,7 @@ bool Slider::onProcessMessage(Message* msg) setupSliderCursor(); - // Fall through + [[fallthrough]]; case kMouseMoveMessage: if (hasCapture()) { diff --git a/src/ui/splitter.cpp b/src/ui/splitter.cpp index c1c6ac9b3..7d539a456 100644 --- a/src/ui/splitter.cpp +++ b/src/ui/splitter.cpp @@ -100,6 +100,7 @@ bool Splitter::onProcessMessage(Message* msg) captureMouse(); // Continue with motion message... + [[fallthrough]]; } else break;