Skip to content

Commit

Permalink
enable -Werror=switch-enum
Browse files Browse the repository at this point in the history
  • Loading branch information
Murmele committed Aug 27, 2023
1 parent 1661a6a commit 989ef27
Show file tree
Hide file tree
Showing 14 changed files with 192 additions and 38 deletions.
2 changes: 2 additions & 0 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -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)
Expand Down
60 changes: 53 additions & 7 deletions src/app/CustomTheme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down Expand Up @@ -435,10 +483,9 @@ QColor CustomTheme::commitEditor(CommitEditor color) {
return commitEditor.value("spellignore").value<QColor>();
case CommitEditor::LengthWarning:
return commitEditor.value("lengthwarning").value<QColor>();
default:
throw std::runtime_error("Not Implemented or invalid enum " +
std::to_string(static_cast<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum " +
std::to_string(static_cast<int>(color)));
}

QColor CustomTheme::diff(Diff color) {
Expand Down Expand Up @@ -467,10 +514,9 @@ QColor CustomTheme::diff(Diff color) {
return diff.value("warning").value<QColor>();
case Diff::Error:
return diff.value("error").value<QColor>();
default:
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}

QColor CustomTheme::heatMap(HeatMap color) {
Expand Down
34 changes: 18 additions & 16 deletions src/app/Theme.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

Expand Down Expand Up @@ -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<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::diff(Diff color) {
Expand Down Expand Up @@ -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<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}

switch (color) {
Expand All @@ -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<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::heatMap(HeatMap color) {
Expand All @@ -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<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::remoteComment(Comment color) {
Expand All @@ -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<int>(color)));
}
throw std::runtime_error("Not Implemented or invalid enum" +
std::to_string(static_cast<int>(color)));
}

QColor Theme::star() { return QPalette().color(QPalette::Highlight); }
Expand Down
2 changes: 1 addition & 1 deletion src/dialogs/ThemeDialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
3 changes: 2 additions & 1 deletion src/editor/PlatQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
21 changes: 18 additions & 3 deletions src/editor/ScintillaQt.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -439,6 +439,7 @@ void ScintillaQt::dragEnterEvent(QDragEnterEvent *event) {
}

void ScintillaQt::dragLeaveEvent(QDragLeaveEvent *event) {
Q_UNUSED(event);
SetDragPosition(SelectionPosition(Sci::invalidPosition));
}

Expand Down Expand Up @@ -567,7 +568,7 @@ void ScintillaQt::inputMethodEvent(QInputMethodEvent *event) {
indicator = SC_INDICATOR_CONVERTED;
break;

default:
case QTextCharFormat::DashDotDotLine:
indicator = SC_INDICATOR_UNKNOWN;
}

Expand Down Expand Up @@ -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) {
Expand Down
3 changes: 2 additions & 1 deletion src/git/Remote.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
14 changes: 13 additions & 1 deletion src/index/GenericLexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
Expand Down
18 changes: 17 additions & 1 deletion src/index/Query.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
29 changes: 27 additions & 2 deletions src/index/indexer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand All @@ -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;
}
}
Expand Down Expand Up @@ -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<MSG *>(message);
if (msg->message == WM_CLOSE)
cancel();
#else
Q_UNUSED(type);
Q_UNUSED(message);
#endif

return false;
Expand Down
8 changes: 7 additions & 1 deletion src/index/lexer_test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/ui/DiffView/HunkWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -785,7 +785,7 @@ void HunkWidget::load(git::Patch &staged, bool force) {
mHeader->theirsButton()->click();
break;

default:
case git::Patch::Unresolved:
break;
}
}
Expand Down
22 changes: 21 additions & 1 deletion src/ui/EditorWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
}
Expand Down
Loading

0 comments on commit 989ef27

Please sign in to comment.