Use proper macro for unreachable switch cases

Those are the `default` cases which are not expected to hit (nor reachable) normally.

When the code is compiled with release mode and it reaches `Q_UNREACHABLE()`, it becomes
undefined behavior. So it rely on the developers to catch the errors in debug mode.
The upside of this is that the `switch` statement will be more optimized than not using it.
This also means the statements after `Q_UNREACHABLE()` isn't important. It allow anything to
preserve the intention of the code.

This macro is preferred over C++23 `std::unreachable` because it will automatically insert a
`Q_ASSERT(false)` with it.

PR #21752.
This commit is contained in:
Chocobo1
2024-11-05 11:55:55 +08:00
committed by GitHub
parent b462a2bf0c
commit 051d7137ea
10 changed files with 27 additions and 17 deletions

View File

@@ -140,9 +140,11 @@ QString TorrentContentModelItem::displayData(const int column) const
return (value + u'%');
}
default:
Q_ASSERT(false);
return {};
Q_UNREACHABLE();
break;
}
return {};
}
QVariant TorrentContentModelItem::underlyingData(const int column) const
@@ -165,9 +167,11 @@ QVariant TorrentContentModelItem::underlyingData(const int column) const
case COL_AVAILABILITY:
return availability();
default:
Q_ASSERT(false);
return {};
Q_UNREACHABLE();
break;
}
return {};
}
int TorrentContentModelItem::row() const