mirror of
https://github.com/qbittorrent/qBittorrent.git
synced 2025-12-20 23:47:23 -06:00
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:
@@ -102,7 +102,7 @@ bool BandwidthScheduler::isTimeForAlternative() const
|
||||
alternative = !alternative;
|
||||
break;
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
Q_UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -296,14 +296,15 @@ namespace
|
||||
{
|
||||
switch (mode)
|
||||
{
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
case MoveStorageMode::FailIfExist:
|
||||
return lt::move_flags_t::fail_if_exist;
|
||||
case MoveStorageMode::KeepExistingFiles:
|
||||
return lt::move_flags_t::dont_replace;
|
||||
case MoveStorageMode::Overwrite:
|
||||
return lt::move_flags_t::always_replace_files;
|
||||
default:
|
||||
Q_UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,7 +160,7 @@ void Connection::read()
|
||||
break;
|
||||
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
Q_UNREACHABLE();
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -153,7 +153,7 @@ QString DNSUpdater::getUpdateUrl() const
|
||||
break;
|
||||
default:
|
||||
qWarning() << "Unrecognized Dynamic DNS service!";
|
||||
Q_ASSERT(false);
|
||||
Q_UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
url.setPath(u"/nic/update"_s);
|
||||
@@ -305,7 +305,7 @@ QUrl DNSUpdater::getRegistrationUrl(const DNS::Service service)
|
||||
case DNS::Service::NoIP:
|
||||
return {u"https://www.noip.com/remote-access"_s};
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
Q_UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
return {};
|
||||
|
||||
@@ -205,9 +205,11 @@ bool TorrentFilter::matchState(const BitTorrent::Torrent *const torrent) const
|
||||
case Errored:
|
||||
return torrent->isErrored();
|
||||
default:
|
||||
Q_ASSERT(false);
|
||||
return false;
|
||||
Q_UNREACHABLE();
|
||||
break;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool TorrentFilter::matchHash(const BitTorrent::Torrent *const torrent) const
|
||||
|
||||
Reference in New Issue
Block a user