Avoid optional::value() and expected::value()

They declare throwing std::bad_(optional|expected)_access,
which some static analyzers do not like in some situations.
And we do not handle these (and always check beforehand) anyway.
Use operator* and operator-> instead.

Change-Id: Ife8c54ff7e872019451163cb4eea7d2629c659ad
Reviewed-by: Christian Stenger <christian.stenger@qt.io>
Reviewed-by: Marcus Tillmanns <marcus.tillmanns@qt.io>
This commit is contained in:
Eike Ziller
2024-09-04 16:11:55 +02:00
parent 452d65b727
commit e92a8402a8
8 changed files with 23 additions and 22 deletions

View File

@@ -1376,7 +1376,7 @@ static QList<PluginSpec *> createCppPluginsFromArchive(const FilePath &path)
it.next();
expected_str<PluginSpec *> spec = readCppPluginSpec(FilePath::fromUserInput(it.filePath()));
if (spec)
results.push_back(spec.value());
results.push_back(*spec);
}
return results;
}

View File

@@ -73,7 +73,7 @@ expected_str<void> FileAccess::deployAndInit(
return make_unexpected(
QString("Could not determine OS on remote host: %1").arg(unameOs.error()));
}
Utils::expected_str<OsType> osType = osTypeFromString(unameOs.value());
Utils::expected_str<OsType> osType = osTypeFromString(*unameOs);
if (!osType)
return make_unexpected(osType.error());
@@ -85,7 +85,7 @@ expected_str<void> FileAccess::deployAndInit(
QString("Could not determine architecture on remote host: %1").arg(unameArch.error()));
}
const Utils::expected_str<OsArch> osArch = osArchFromString(unameArch.value());
const Utils::expected_str<OsArch> osArch = osArchFromString(*unameArch);
if (!osArch)
return make_unexpected(osArch.error());

View File

@@ -91,7 +91,7 @@ void TestResultDelegate::paint(QPainter *painter, const QStyleOptionViewItem &op
}
if (testResult.result() == ResultType::TestStart && m_showDuration && testResult.duration()) {
const QString txt = testResult.duration().value() + " ms";
const QString txt = *testResult.duration() + " ms";
QPen tmp = painter->pen();
painter->setPen(opt.palette.mid().color());
painter->setClipRect(positions.durationArea());

View File

@@ -806,7 +806,7 @@ Group issueTableRecipe(const IssueListSearch &search, const IssueTableHandler &h
if (query.isEmpty())
return {}; // TODO: Call handler with unexpected?
const QUrl url = constructUrl(dd->m_currentProjectInfo.value().name, "issues", query);
const QUrl url = constructUrl(dd->m_currentProjectInfo->name, "issues", query);
return fetchDataRecipe<Dto::IssueTableDto>(url, handler);
}
@@ -818,7 +818,7 @@ Group lineMarkerRecipe(const FilePath &filePath, const LineMarkerHandler &handle
const QString fileName = QString::fromUtf8(QUrl::toPercentEncoding(filePath.path()));
const QUrlQuery query({{"filename", fileName}, {"version", *dd->m_analysisVersion}});
const QUrl url = constructUrl(dd->m_currentProjectInfo.value().name, "files", query);
const QUrl url = constructUrl(dd->m_currentProjectInfo->name, "files", query);
return fetchDataRecipe<Dto::FileViewDto>(url, handler);
}
@@ -830,7 +830,7 @@ Group fileSourceRecipe(const FilePath &filePath, const std::function<void(const
const QString fileName = QString::fromUtf8(QUrl::toPercentEncoding(filePath.path()));
const QUrlQuery query({{"filename", fileName}, {"version", *dd->m_analysisVersion}});
const QUrl url = constructUrl(dd->m_currentProjectInfo.value().name, "sourcecode", query);
const QUrl url = constructUrl(dd->m_currentProjectInfo->name, "sourcecode", query);
return fetchPlainTextRecipe(url, handler);
}
@@ -839,9 +839,10 @@ Group issueHtmlRecipe(const QString &issueId, const HtmlHandler &handler)
QTC_ASSERT(dd->m_currentProjectInfo, return {}); // TODO: Call handler with unexpected?
QTC_ASSERT(dd->m_analysisVersion, return {}); // TODO: Call handler with unexpected?
const QUrl url = constructUrl(dd->m_currentProjectInfo.value().name,
QString("issues/" + issueId + "/properties/"),
{{"version", *dd->m_analysisVersion}});
const QUrl url = constructUrl(
dd->m_currentProjectInfo->name,
QString("issues/" + issueId + "/properties/"),
{{"version", *dd->m_analysisVersion}});
return fetchHtmlRecipe(url, handler);
}
@@ -894,7 +895,7 @@ void AxivionPluginPrivate::fetchProjectInfo(const QString &projectName)
Group tableInfoRecipe(const QString &prefix, const TableInfoHandler &handler)
{
const QUrlQuery query({{"kind", prefix}});
const QUrl url = constructUrl(dd->m_currentProjectInfo.value().name, "issues_meta", query);
const QUrl url = constructUrl(dd->m_currentProjectInfo->name, "issues_meta", query);
return fetchDataRecipe<Dto::TableInfoDto>(url, handler);
}

View File

@@ -142,7 +142,7 @@ static QIcon iconForSorted(std::optional<Qt::SortOrder> order)
if (!order)
return unsorted;
return order.value() == Qt::AscendingOrder ? sortedAsc : sortedDesc;
return *order == Qt::AscendingOrder ? sortedAsc : sortedDesc;
}
static QIcon iconForFilter(bool isActive)
@@ -173,7 +173,7 @@ QList<QPair<int, Qt::SortOrder>> IssueHeaderView::currentSortColumns() const
{
QList<QPair<int, Qt::SortOrder>> result;
for (int i : m_currentSortIndexes)
result.append({i, m_columnInfoList.at(i).sortOrder.value()});
result.append({i, *m_columnInfoList.at(i).sortOrder});
return result;
}
@@ -183,7 +183,7 @@ QList<QPair<int, QString>> IssueHeaderView::currentFilterColumns() const
for (int i = 0, end = m_columnInfoList.size(); i < end; ++i) {
const ColumnInfo ci = m_columnInfoList.at(i);
if (ci.filter.has_value())
result.append({i, ci.filter.value()});
result.append({i, *ci.filter});
}
return result;
}
@@ -225,7 +225,7 @@ void IssueHeaderView::mousePressEvent(QMouseEvent *event)
void IssueHeaderView::mouseReleaseEvent(QMouseEvent *event)
{
bool dontSkip = !m_dragging && m_maybeToggle;
const int toggleMode = m_maybeToggle ? m_maybeToggle.value() : -1;
const int toggleMode = m_maybeToggle ? *m_maybeToggle : -1;
bool withShift = m_withShift && event->modifiers() == Qt::ShiftModifier;
m_dragging = false;
m_maybeToggle.reset();

View File

@@ -35,7 +35,7 @@ ClangFormatFile::ClangFormatFile(
0,
"# yaml-language-server: "
"$schema=https://json.schemastore.org/clang-format.json\n");
m_filePath.writeFileContents(fileContent.value());
m_filePath.writeFileContents(*fileContent);
}
parseConfigurationFile(m_filePath, m_style);
return;

View File

@@ -856,7 +856,7 @@ QStringList DockerDevicePrivate::createMountArgs() const
mounts.append({m, m});
if (cmdBridgePath && cmdBridgePath->isSameDevice(settings().dockerBinaryPath()))
mounts.append({cmdBridgePath.value(), FilePath("/tmp/_qtc_cmdbridge")});
mounts.append({*cmdBridgePath, FilePath("/tmp/_qtc_cmdbridge")});
for (const MountPair &mi : mounts) {
if (isValidMountInfo(mi))
@@ -1363,7 +1363,7 @@ expected_str<Environment> DockerDevicePrivate::environment()
}
QTC_ASSERT(m_cachedEnviroment, return {});
return m_cachedEnviroment.value();
return *m_cachedEnviroment;
}
void DockerDevicePrivate::shutdown()

View File

@@ -237,7 +237,7 @@ void tst_PluginSpec::locationAndPath()
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
CppPluginSpec *spec = static_cast<CppPluginSpec *>(*ps);
QCOMPARE(spec->location(), PLUGIN_DIR_PATH / "testplugin");
QCOMPARE(spec->filePath(), PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
}
@@ -292,7 +292,7 @@ void tst_PluginSpec::loadLibrary()
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
CppPluginSpec *spec = static_cast<CppPluginSpec *>(*ps);
QCOMPARE(spec->errorString(), QString());
QVERIFY(spec->resolveDependencies({}));
@@ -311,7 +311,7 @@ void tst_PluginSpec::initializePlugin()
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
CppPluginSpec *spec = static_cast<CppPluginSpec *>(*ps);
QVERIFY(spec->resolveDependencies({}));
QVERIFY2(spec->loadLibrary(), qPrintable(spec->errorString()));
bool isInitialized;
@@ -335,7 +335,7 @@ void tst_PluginSpec::initializeExtensions()
Utils::expected_str<PluginSpec *> ps = readCppPluginSpec(
PLUGIN_DIR_PATH / "testplugin" / libraryName(QLatin1String("test")));
QVERIFY(ps);
CppPluginSpec *spec = static_cast<CppPluginSpec *>(ps.value());
CppPluginSpec *spec = static_cast<CppPluginSpec *>(*ps);
QVERIFY(spec->resolveDependencies({}));
QVERIFY2(spec->loadLibrary(), qPrintable(spec->errorString()));
bool isExtensionsInitialized;