https://invent.kde.org/plasma/kwin/-/merge_requests/7191
https://bugs.kde.org/show_bug.cgi?id=500310
https://gcc.gnu.org/bugzilla/show_bug.cgi?id=118923

From 4d9a024f1b2f502de9a33024a2a762aefa4007cd Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Kacper=20S=C5=82omi=C5=84ski?=
 <kacper.slominski72@gmail.com>
Date: Tue, 18 Feb 2025 18:16:59 +0100
Subject: [PATCH] Factor out {previousRestricted,restricted}MoveArea calls out
 of loops

This works around a GCC 15 bug that causes KWin to crash.

BUG: 500310
---
 src/window.cpp | 24 ++++++++++++++++--------
 1 file changed, 16 insertions(+), 8 deletions(-)

diff --git a/src/window.cpp b/src/window.cpp
index a05771e90c..1a56560280 100644
--- a/src/window.cpp
+++ b/src/window.cpp
@@ -4026,25 +4026,29 @@ void Window::checkWorkspacePosition(QRectF oldGeometry, const VirtualDesktop *ol
     auto moveAreaFunc = workspace()->inRearrange() ? &Workspace::previousRestrictedMoveArea : //... the restricted areas changed
         &Workspace::restrictedMoveArea; //... when e.g. active desktop or screen changes
 
-    for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop)) {
+    const auto oldRectsTop = (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaTop);
+    for (const QRect &r : oldRectsTop) {
         QRect rect = r & oldGeomTall;
         if (!rect.isEmpty()) {
             oldTopMax = std::max(oldTopMax, rect.y() + rect.height());
         }
     }
-    for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaRight)) {
+    const auto oldRectsRight = (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaRight);
+    for (const QRect &r : oldRectsRight) {
         QRect rect = r & oldGeomWide;
         if (!rect.isEmpty()) {
             oldRightMax = std::min(oldRightMax, rect.x());
         }
     }
-    for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaBottom)) {
+    const auto oldRectsBottom = (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaBottom);
+    for (const QRect &r : oldRectsBottom) {
         QRect rect = r & oldGeomTall;
         if (!rect.isEmpty()) {
             oldBottomMax = std::min(oldBottomMax, rect.y());
         }
     }
-    for (const QRect &r : (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaLeft)) {
+    const auto oldRectsLeft = (workspace()->*moveAreaFunc)(oldDesktop, StrutAreaLeft);
+    for (const QRect &r : oldRectsLeft) {
         QRect rect = r & oldGeomWide;
         if (!rect.isEmpty()) {
             oldLeftMax = std::max(oldLeftMax, rect.x() + rect.width());
@@ -4052,25 +4056,29 @@ void Window::checkWorkspacePosition(QRectF oldGeometry, const VirtualDesktop *ol
     }
 
     // These 4 compute new bounds
-    for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaTop)) {
+    const auto newRectsTop = workspace()->restrictedMoveArea(desktop, StrutAreaTop);
+    for (const QRect &r : newRectsTop) {
         QRect rect = r & newGeomTall;
         if (!rect.isEmpty()) {
             topMax = std::max(topMax, rect.y() + rect.height());
         }
     }
-    for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaRight)) {
+    const auto newRectsRight = workspace()->restrictedMoveArea(desktop, StrutAreaRight);
+    for (const QRect &r : newRectsRight) {
         QRect rect = r & newGeomWide;
         if (!rect.isEmpty()) {
             rightMax = std::min(rightMax, rect.x());
         }
     }
-    for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaBottom)) {
+    const auto newRectsBottom = workspace()->restrictedMoveArea(desktop, StrutAreaBottom);
+    for (const QRect &r : newRectsBottom) {
         QRect rect = r & newGeomTall;
         if (!rect.isEmpty()) {
             bottomMax = std::min(bottomMax, rect.y());
         }
     }
-    for (const QRect &r : workspace()->restrictedMoveArea(desktop, StrutAreaLeft)) {
+    const auto newRectsLeft = workspace()->restrictedMoveArea(desktop, StrutAreaLeft);
+    for (const QRect &r : newRectsLeft) {
         QRect rect = r & newGeomWide;
         if (!rect.isEmpty()) {
             leftMax = std::max(leftMax, rect.x() + rect.width());
-- 
GitLab
