From 5f83f2a78170256bf18429640900c70717d74a43 Mon Sep 17 00:00:00 2001 From: Vlad Zahorodnii Date: Tue, 4 Jan 2022 10:28:42 +0200 Subject: [PATCH] Replace abort() with Q_ASSERT and Q_UNREACHABLE This change replaces abort() with Q_ASSERT and Q_UNREACHABLE() macros to make kwin code base consistent. Besides that, Q_UNREACHABLE may potentially provide the compiler more info that can be used to generate more efficient machine code. --- src/abstract_client.cpp | 7 ++++--- src/backends/libinput/events.cpp | 6 ++++-- src/effects.cpp | 4 ++-- src/effects/presentwindows/presentwindows.cpp | 2 +- src/kcmkwin/kwinscreenedges/monitor.cpp | 6 +++--- src/libkwineffects/kwineffects.cpp | 3 +-- src/useractions.cpp | 5 +++-- src/workspace.cpp | 4 ++-- src/x11client.cpp | 4 ++-- 9 files changed, 22 insertions(+), 19 deletions(-) diff --git a/src/abstract_client.cpp b/src/abstract_client.cpp index 16b2c0df8b..4d5ea99b79 100644 --- a/src/abstract_client.cpp +++ b/src/abstract_client.cpp @@ -1237,7 +1237,7 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y break; case PositionCenter: default: - abort(); + Q_UNREACHABLE(); break; } }; @@ -1442,8 +1442,9 @@ void AbstractClient::handleInteractiveMoveResize(int x, int y, int x_root, int y } if (moveResizeGeometry().topLeft() != previousMoveResizeGeom.topLeft()) update = true; - } else - abort(); + } else { + Q_UNREACHABLE(); + } if (!update) return; diff --git a/src/backends/libinput/events.cpp b/src/backends/libinput/events.cpp index f995775fef..6ae200ffb1 100644 --- a/src/backends/libinput/events.cpp +++ b/src/backends/libinput/events.cpp @@ -116,8 +116,9 @@ InputRedirection::KeyboardKeyState KeyEvent::state() const return InputRedirection::KeyboardKeyPressed; case LIBINPUT_KEY_STATE_RELEASED: return InputRedirection::KeyboardKeyReleased; + default: + Q_UNREACHABLE(); } - abort(); } uint32_t KeyEvent::time() const @@ -183,8 +184,9 @@ InputRedirection::PointerButtonState PointerEvent::buttonState() const return InputRedirection::PointerButtonPressed; case LIBINPUT_BUTTON_STATE_RELEASED: return InputRedirection::PointerButtonReleased; + default: + Q_UNREACHABLE(); } - abort(); } QVector PointerEvent::axis() const diff --git a/src/effects.cpp b/src/effects.cpp index e8cd375c45..26cdd60984 100644 --- a/src/effects.cpp +++ b/src/effects.cpp @@ -1857,7 +1857,7 @@ void EffectWindowImpl::refWindow() if (auto d = qobject_cast(toplevel)) { return d->refWindow(); } - abort(); // TODO + Q_UNREACHABLE(); // TODO } void EffectWindowImpl::unrefWindow() @@ -1865,7 +1865,7 @@ void EffectWindowImpl::unrefWindow() if (auto d = qobject_cast(toplevel)) { return d->unrefWindow(); // delays deletion in case } - abort(); // TODO + Q_UNREACHABLE(); // TODO } EffectScreen *EffectWindowImpl::screen() const diff --git a/src/effects/presentwindows/presentwindows.cpp b/src/effects/presentwindows/presentwindows.cpp index fe5df93222..c8bf3084c7 100644 --- a/src/effects/presentwindows/presentwindows.cpp +++ b/src/effects/presentwindows/presentwindows.cpp @@ -1998,7 +1998,7 @@ EffectWindow* PresentWindowsEffect::relativeWindow(EffectWindow *w, int xdiff, i } } - abort(); // Should never get here + Q_UNREACHABLE(); // Should never get here } EffectWindow* PresentWindowsEffect::findFirstWindow() const diff --git a/src/kcmkwin/kwinscreenedges/monitor.cpp b/src/kcmkwin/kwinscreenedges/monitor.cpp index 6a7a421aef..3f64908318 100644 --- a/src/kcmkwin/kwinscreenedges/monitor.cpp +++ b/src/kcmkwin/kwinscreenedges/monitor.cpp @@ -189,7 +189,7 @@ int Monitor::selectedEdgeItem(int edge) const return actions.indexOf(act); } } - abort(); + Q_UNREACHABLE(); } void Monitor::popup(Corner* c, QPoint pos) @@ -209,7 +209,7 @@ void Monitor::popup(Corner* c, QPoint pos) return; } } - abort(); + Q_UNREACHABLE(); } void Monitor::flip(Corner* c, QPoint pos) @@ -225,7 +225,7 @@ void Monitor::flip(Corner* c, QPoint pos) return; } } - abort(); + Q_UNREACHABLE(); } Monitor::Corner::Corner(Monitor* m) diff --git a/src/libkwineffects/kwineffects.cpp b/src/libkwineffects/kwineffects.cpp index 6b7bb185f8..ccb5037439 100644 --- a/src/libkwineffects/kwineffects.cpp +++ b/src/libkwineffects/kwineffects.cpp @@ -1382,8 +1382,7 @@ void WindowMotionManager::apply(EffectWindow *w, WindowPaintData &data) void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scale, double yScale) { QHash::iterator it = m_managedWindows.find(w); - if (it == m_managedWindows.end()) - abort(); // Notify the effect author that they did something wrong + Q_ASSERT(it != m_managedWindows.end()); // Notify the effect author that they did something wrong WindowMotion *motion = &it.value(); diff --git a/src/useractions.cpp b/src/useractions.cpp index e499e2694a..86c80174a2 100644 --- a/src/useractions.cpp +++ b/src/useractions.cpp @@ -179,8 +179,9 @@ void UserActionsMenu::helperDialog(const QString& message, AbstractClient* clien "activated using the %1 keyboard shortcut.", shortcut(QStringLiteral("Window Operations Menu"))); type = QStringLiteral("altf3warning"); - } else - abort(); + } else { + Q_UNREACHABLE(); + } if (!type.isEmpty()) { KConfig cfg(QStringLiteral("kwin_dialogsrc")); KConfigGroup cg(&cfg, "Notification Messages"); // Depends on KMessageBox diff --git a/src/workspace.cpp b/src/workspace.cpp index 2d0b7ff091..b425e558ae 100644 --- a/src/workspace.cpp +++ b/src/workspace.cpp @@ -2718,7 +2718,7 @@ QRect Workspace::adjustClientSize(AbstractClient* c, QRect moveResizeGeom, int m SNAP_BORDER_LEFT break; default: - abort(); + Q_UNREACHABLE(); break; } @@ -2846,7 +2846,7 @@ QRect Workspace::adjustClientSize(AbstractClient* c, QRect moveResizeGeom, int m SNAP_WINDOW_C_LEFT break; default: - abort(); + Q_UNREACHABLE(); break; } } diff --git a/src/x11client.cpp b/src/x11client.cpp index d815e519b3..9ec86cea82 100644 --- a/src/x11client.cpp +++ b/src/x11client.cpp @@ -1189,7 +1189,7 @@ void X11Client::detectNoBorder() noborder = false; break; default: - abort(); + Q_UNREACHABLE(); } // NET::Override is some strange beast without clear definition, usually // just meaning "noborder", so let's treat it only as such flag, and ignore it as @@ -4660,7 +4660,7 @@ StrutRect X11Client::strutRect(StrutArea area) const ), StrutAreaLeft); break; default: - abort(); // Not valid + Q_UNREACHABLE(); // Not valid } return StrutRect(); // Null rect }