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.
This commit is contained in:
Vlad Zahorodnii 2022-01-04 10:28:42 +02:00
parent dde3010353
commit 5f83f2a781
9 changed files with 22 additions and 19 deletions

View file

@ -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;

View file

@ -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<InputRedirection::PointerAxis> PointerEvent::axis() const

View file

@ -1857,7 +1857,7 @@ void EffectWindowImpl::refWindow()
if (auto d = qobject_cast<Deleted *>(toplevel)) {
return d->refWindow();
}
abort(); // TODO
Q_UNREACHABLE(); // TODO
}
void EffectWindowImpl::unrefWindow()
@ -1865,7 +1865,7 @@ void EffectWindowImpl::unrefWindow()
if (auto d = qobject_cast<Deleted *>(toplevel)) {
return d->unrefWindow(); // delays deletion in case
}
abort(); // TODO
Q_UNREACHABLE(); // TODO
}
EffectScreen *EffectWindowImpl::screen() const

View file

@ -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

View file

@ -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)

View file

@ -1382,8 +1382,7 @@ void WindowMotionManager::apply(EffectWindow *w, WindowPaintData &data)
void WindowMotionManager::moveWindow(EffectWindow *w, QPoint target, double scale, double yScale)
{
QHash<EffectWindow*, WindowMotion>::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();

View file

@ -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

View file

@ -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;
}
}

View file

@ -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
}