From 989ef27bcb2515c94f7a9cd99f9605930cfa109f Mon Sep 17 00:00:00 2001 From: Martin Marmsoler Date: Sun, 27 Aug 2023 14:31:27 +0200 Subject: [PATCH] enable -Werror=switch-enum --- src/CMakeLists.txt | 2 ++ src/app/CustomTheme.cpp | 60 ++++++++++++++++++++++++++++++---- src/app/Theme.cpp | 34 ++++++++++--------- src/dialogs/ThemeDialog.cpp | 2 +- src/editor/PlatQt.cpp | 3 +- src/editor/ScintillaQt.cpp | 21 ++++++++++-- src/git/Remote.cpp | 3 +- src/index/GenericLexer.cpp | 14 +++++++- src/index/Query.cpp | 18 +++++++++- src/index/indexer.cpp | 29 ++++++++++++++-- src/index/lexer_test.cpp | 8 ++++- src/ui/DiffView/HunkWidget.cpp | 2 +- src/ui/EditorWindow.cpp | 22 ++++++++++++- src/ui/FileContextMenu.cpp | 12 +++++-- 14 files changed, 192 insertions(+), 38 deletions(-) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 0a370e7b1..740878682 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,5 +1,7 @@ include_directories(${CMAKE_CURRENT_SOURCE_DIR}) +add_compile_options(-Werror=switch-enum) + add_subdirectory(util) add_subdirectory(cli) add_subdirectory(conf) diff --git a/src/app/CustomTheme.cpp b/src/app/CustomTheme.cpp index 75926c928..87ab6bc6c 100644 --- a/src/app/CustomTheme.cpp +++ b/src/app/CustomTheme.cpp @@ -73,7 +73,55 @@ class CustomStyle : public QProxyStyle { CustomTheme::drawCloseButton(option, painter); break; - default: + case PE_Frame: // fall through + case PE_FrameDefaultButton: // fall through + case PE_FrameDockWidget: // fall through + case PE_FrameFocusRect: // fall through + case PE_FrameGroupBox: // fall through + case PE_FrameLineEdit: // fall through + case PE_FrameMenu: // fall through + case PE_FrameStatusBarItem: // fall through + case PE_FrameTabWidget: // fall through + case PE_FrameWindow: // fall through + case PE_FrameButtonBevel: // fall through + case PE_FrameButtonTool: // fall through + case PE_FrameTabBarBase: // fall through + case PE_PanelButtonCommand: // fall through + case PE_PanelButtonBevel: // fall through + case PE_PanelButtonTool: // fall through + case PE_PanelMenuBar: // fall through + case PE_PanelToolBar: // fall through + case PE_PanelLineEdit: // fall through + case PE_IndicatorArrowDown: // fall through + case PE_IndicatorArrowLeft: // fall through + case PE_IndicatorArrowRight: // fall through + case PE_IndicatorArrowUp: // fall through + case PE_IndicatorBranch: // fall through + case PE_IndicatorButtonDropDown: // fall through + case PE_IndicatorItemViewItemCheck: // fall through + case PE_IndicatorDockWidgetResizeHandle: // fall through + case PE_IndicatorHeaderArrow: // fall through + case PE_IndicatorMenuCheckMark: // fall through + case PE_IndicatorProgressChunk: // fall through + case PE_IndicatorRadioButton: // fall through + case PE_IndicatorSpinDown: // fall through + case PE_IndicatorSpinMinus: // fall through + case PE_IndicatorSpinPlus: // fall through + case PE_IndicatorSpinUp: // fall through + case PE_IndicatorToolBarHandle: // fall through + case PE_IndicatorToolBarSeparator: // fall through + case PE_PanelTipLabel: // fall through + case PE_IndicatorTabTear: // fall through + case PE_PanelScrollAreaCorner: // fall through + case PE_Widget: // fall through + case PE_IndicatorColumnViewArrow: // fall through + case PE_IndicatorItemViewItemDrop: // fall through + case PE_PanelItemViewItem: // fall through + case PE_PanelItemViewRow: // fall through + case PE_PanelStatusBar: // fall through + case PE_PanelMenu: // fall through + case PE_IndicatorTabTearRight: // fall through + case PE_CustomBase: // fall through baseStyle()->drawPrimitive(elem, option, painter, widget); break; } @@ -435,10 +483,9 @@ QColor CustomTheme::commitEditor(CommitEditor color) { return commitEditor.value("spellignore").value(); case CommitEditor::LengthWarning: return commitEditor.value("lengthwarning").value(); - default: - throw std::runtime_error("Not Implemented or invalid enum " + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum " + + std::to_string(static_cast(color))); } QColor CustomTheme::diff(Diff color) { @@ -467,10 +514,9 @@ QColor CustomTheme::diff(Diff color) { return diff.value("warning").value(); case Diff::Error: return diff.value("error").value(); - default: - throw std::runtime_error("Not Implemented or invalid enum" + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum" + + std::to_string(static_cast(color))); } QColor CustomTheme::heatMap(HeatMap color) { diff --git a/src/app/Theme.cpp b/src/app/Theme.cpp index 31d154ed4..23deb2381 100644 --- a/src/app/Theme.cpp +++ b/src/app/Theme.cpp @@ -101,7 +101,14 @@ QColor Theme::badge(BadgeRole role, BadgeState state) { case BadgeState::Head: return QPalette().color(QPalette::HighlightedText); - default: + case BadgeState::Normal: // fall through + case BadgeState::Conflicted: // fall through + case BadgeState::Notification: // fall through + case BadgeState::Modified: // fall through + case BadgeState::Added: // fall through + case BadgeState::Deleted: // fall through + case BadgeState::Untracked: // fall through + case BadgeState::Renamed: return QPalette().color(QPalette::WindowText); } @@ -163,10 +170,9 @@ QColor Theme::commitEditor(CommitEditor color) { return Qt::gray; case CommitEditor::LengthWarning: return Qt::yellow; - default: - throw std::runtime_error("Not Implemented or invalid enum" + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum" + + std::to_string(static_cast(color))); } QColor Theme::diff(Diff color) { @@ -194,10 +200,9 @@ QColor Theme::diff(Diff color) { return "#E8C080"; case Diff::Error: return "#7E494B"; - default: - throw std::runtime_error("Not Implemented or invalid enum" + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum" + + std::to_string(static_cast(color))); } switch (color) { @@ -223,10 +228,9 @@ QColor Theme::diff(Diff color) { return "#FFFF00"; case Diff::Error: return "#FF0000"; - default: - throw std::runtime_error("Not Implemented or invalid enum" + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum" + + std::to_string(static_cast(color))); } QColor Theme::heatMap(HeatMap color) { @@ -236,10 +240,9 @@ QColor Theme::heatMap(HeatMap color) { case HeatMap::Cold: return mDark ? QPalette().color(QPalette::Inactive, QPalette::Highlight) : QPalette().color(QPalette::Mid); - default: - throw std::runtime_error("Not Implemented or invalid enum" + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum" + + std::to_string(static_cast(color))); } QColor Theme::remoteComment(Comment color) { @@ -252,10 +255,9 @@ QColor Theme::remoteComment(Comment color) { return QPalette().color(QPalette::WindowText); case Comment::Timestamp: return QPalette().color(QPalette::WindowText); - default: - throw std::runtime_error("Not Implemented or invalid enum" + - std::to_string(static_cast(color))); } + throw std::runtime_error("Not Implemented or invalid enum" + + std::to_string(static_cast(color))); } QColor Theme::star() { return QPalette().color(QPalette::Highlight); } diff --git a/src/dialogs/ThemeDialog.cpp b/src/dialogs/ThemeDialog.cpp index c5ca00cb4..58fcb45be 100644 --- a/src/dialogs/ThemeDialog.cpp +++ b/src/dialogs/ThemeDialog.cpp @@ -62,7 +62,7 @@ class ThemeButton : public QPushButton { case Theme::Dark: Settings::instance()->setValue(Setting::Id::ColorTheme, "Dark"); break; - default: + case Theme::Default: Settings::instance()->setValue(Setting::Id::ColorTheme, "Default"); break; } diff --git a/src/editor/PlatQt.cpp b/src/editor/PlatQt.cpp index 5d866e2d6..696cd1cca 100644 --- a/src/editor/PlatQt.cpp +++ b/src/editor/PlatQt.cpp @@ -486,7 +486,8 @@ void Window::SetCursor(Cursor curs) { case cursorHand: shape = Qt::PointingHandCursor; break; - default: + case cursorInvalid: // fall through + case cursorReverseArrow: shape = Qt::ArrowCursor; break; } diff --git a/src/editor/ScintillaQt.cpp b/src/editor/ScintillaQt.cpp index bfdf6c3ba..8b6e3e21d 100644 --- a/src/editor/ScintillaQt.cpp +++ b/src/editor/ScintillaQt.cpp @@ -439,6 +439,7 @@ void ScintillaQt::dragEnterEvent(QDragEnterEvent *event) { } void ScintillaQt::dragLeaveEvent(QDragLeaveEvent *event) { + Q_UNUSED(event); SetDragPosition(SelectionPosition(Sci::invalidPosition)); } @@ -567,7 +568,7 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) { indicator = SC_INDICATOR_CONVERTED; break; - default: + case QTextCharFormat::DashDotDotLine: indicator = SC_INDICATOR_UNKNOWN; } @@ -690,9 +691,23 @@ QVariant ScintillaQt::inputMethodQuery(Qt::InputMethodQuery query) const { return buffer.constData(); } - default: - return QVariant(); + case Qt::ImEnabled: // fall through + case Qt::ImAnchorPosition: // fall through + case Qt::ImHints: // fall through + case Qt::ImMaximumTextLength: // fall through + case Qt::ImPreferredLanguage: // fall through + case Qt::ImAbsolutePosition: // fall through + case Qt::ImTextBeforeCursor: // fall through + case Qt::ImTextAfterCursor: // fall through + case Qt::ImEnterKeyType: // fall through + case Qt::ImAnchorRectangle: // fall through + case Qt::ImInputItemClipRectangle: // fall through + case Qt::ImPlatformData: // fall through + case Qt::ImQueryInput: // fall through + case Qt::ImQueryAll: // fall through + break; } + return QVariant(); } void ScintillaQt::PasteFromMode(QClipboard::Mode clipboardMode) { diff --git a/src/git/Remote.cpp b/src/git/Remote.cpp index d5d6c8a56..dfd1013ba 100644 --- a/src/git/Remote.cpp +++ b/src/git/Remote.cpp @@ -445,9 +445,10 @@ int Remote::Callbacks::transfer(const git_indexer_progress *stats, case Resolve: return cbs->resolve(stats->total_deltas, stats->indexed_deltas) ? 0 : -1; - default: + case Update: return 0; } + return 0; } int Remote::Callbacks::update(const char *name, const git_oid *a, diff --git a/src/index/GenericLexer.cpp b/src/index/GenericLexer.cpp index 6851e9102..d0ea3dc23 100644 --- a/src/index/GenericLexer.cpp +++ b/src/index/GenericLexer.cpp @@ -93,7 +93,19 @@ Lexer::Lexeme GenericLexer::next() { } break; - default: + case Comment: // fall through + case Keyword: // fall through + case Operator: // fall through + case Error: // fall through + case Preprocessor: // fall through + case Constant: // fall through + case Variable: // fall through + case Function: // fall through + case Class: // fall through + case Type: // fall through + case Label: // fall through + case Regex: // fall through + case Embedded: // fall through Q_ASSERT(false); } } diff --git a/src/index/Query.cpp b/src/index/Query.cpp index 11d143085..e64cb2090 100644 --- a/src/index/Query.cpp +++ b/src/index/Query.cpp @@ -74,7 +74,23 @@ class DateRangeQuery : public TermQuery { return (tmp < date); case Index::After: return (tmp > date); - default: + case Index::Id: // fall through + case Index::Author: // fall through + case Index::Email: // fall through + case Index::Message: // fall through + case Index::Date: // fall through + case Index::Path: // fall through + case Index::File: // fall through + case Index::Scope: // fall through + case Index::Context: // fall through + case Index::Addition: // fall through + case Index::Deletion: // fall through + case Index::Any: // fall through + case Index::Comment: // fall through + case Index::String: // fall through + case Index::Identifier: // fall through + case Index::Is: // fall through + case Index::Pathspec: Q_ASSERT(false); return false; } diff --git a/src/index/indexer.cpp b/src/index/indexer.cpp index f6111e953..29a8f4054 100644 --- a/src/index/indexer.cpp +++ b/src/index/indexer.cpp @@ -149,7 +149,22 @@ void index(const Lexer::Lexeme &lexeme, Intermediate::FieldMap &fields, case Lexer::Comment: field |= Index::Comment; break; - default: + case Lexer::Nothing: // fall through + case Lexer::Whitespace: // fall through + case Lexer::Number: // fall through + case Lexer::Keyword: // fall through + case Lexer::Identifier: // fall through + case Lexer::Operator: // fall through + case Lexer::Error: // fall through + case Lexer::Preprocessor: // fall through + case Lexer::Constant: // fall through + case Lexer::Variable: // fall through + case Lexer::Function: // fall through + case Lexer::Class: // fall through + case Lexer::Type: // fall through + case Lexer::Label: // fall through + case Lexer::Regex: // fall through + case Lexer::Embedded: // fall through break; } @@ -173,7 +188,13 @@ void index(const Lexer::Lexeme &lexeme, Intermediate::FieldMap &fields, break; // Ignore everything else. - default: + case Lexer::Nothing: // fall through + case Lexer::Whitespace: // fall through + case Lexer::Number: // fall through + case Lexer::Operator: // fall through + case Lexer::Error: // fall through + case Lexer::Regex: // fall through + case Lexer::Embedded: // fall through break; } } @@ -456,10 +477,14 @@ class Indexer : public QObject, public QAbstractNativeEventFilter { bool nativeEventFilter(const QByteArray &type, void *message, long *result) override { + Q_UNUSED(result); #ifdef Q_OS_WIN MSG *msg = static_cast(message); if (msg->message == WM_CLOSE) cancel(); +#else + Q_UNUSED(type); + Q_UNUSED(message); #endif return false; diff --git a/src/index/lexer_test.cpp b/src/index/lexer_test.cpp index 8f58dd5f6..4bfaba096 100644 --- a/src/index/lexer_test.cpp +++ b/src/index/lexer_test.cpp @@ -66,7 +66,13 @@ void print(QTextStream &out, Lexer *lexer, int indent = 0) { break; // Ignore everything else. - default: + case Lexer::Whitespace: // fall through + case Lexer::Nothing: // fall through + case Lexer::Number: // fall through + case Lexer::Operator: // fall through + case Lexer::Error: // fall through + case Lexer::Regex: // fall through + case Lexer::Embedded: break; } } diff --git a/src/ui/DiffView/HunkWidget.cpp b/src/ui/DiffView/HunkWidget.cpp index 1619cd0b0..65d5f5396 100644 --- a/src/ui/DiffView/HunkWidget.cpp +++ b/src/ui/DiffView/HunkWidget.cpp @@ -785,7 +785,7 @@ void HunkWidget::load(git::Patch &staged, bool force) { mHeader->theirsButton()->click(); break; - default: + case git::Patch::Unresolved: break; } } diff --git a/src/ui/EditorWindow.cpp b/src/ui/EditorWindow.cpp index 12ec3ce91..0e327bed4 100644 --- a/src/ui/EditorWindow.cpp +++ b/src/ui/EditorWindow.cpp @@ -97,7 +97,27 @@ void EditorWindow::closeEvent(QCloseEvent *event) { case QMessageBox::Save: editor->save(); break; - default: + case QMessageBox::NoButton: + case QMessageBox::SaveAll: + case QMessageBox::Open: + case QMessageBox::Yes: + case QMessageBox::No: + case QMessageBox::Abort: + case QMessageBox::Retry: + case QMessageBox::Ignore: + case QMessageBox::Close: + case QMessageBox::Discard: + case QMessageBox::Help: + case QMessageBox::Apply: + case QMessageBox::Reset: + case QMessageBox::RestoreDefaults: + case QMessageBox::FirstButton: + case QMessageBox::YesAll: + case QMessageBox::NoAll: + case QMessageBox::Default: + case QMessageBox::Escape: + case QMessageBox::FlagMask: + case QMessageBox::ButtonMask: break; } } diff --git a/src/ui/FileContextMenu.cpp b/src/ui/FileContextMenu.cpp index 9c46b9baf..b7e184b24 100644 --- a/src/ui/FileContextMenu.cpp +++ b/src/ui/FileContextMenu.cpp @@ -71,7 +71,14 @@ void handlePath(const git::Repository &repo, const QString &path, untracked.append(path); break; - default: + case GIT_DELTA_UNMODIFIED: // fall through + case GIT_DELTA_ADDED: // fall through + case GIT_DELTA_RENAMED: // fall through + case GIT_DELTA_COPIED: // fall through + case GIT_DELTA_IGNORED: // fall through + case GIT_DELTA_TYPECHANGE: // fall through + case GIT_DELTA_UNREADABLE: // fall through + case GIT_DELTA_CONFLICTED: // fall through break; } } @@ -115,7 +122,8 @@ FileContextMenu::FileContextMenu(RepoView *view, const QStringList &files, mergeTools.append(tool); break; - default: + case ExternalTool::Show: // fall through + case ExternalTool::Edit: Q_ASSERT(false); break; }