Fix warning: "Don't call QVector::first() on temporary QList/QVector"

[-Wclazy-detaching-temporary]

Change-Id: I23f5cbd80bb92d3f9f1bfb5ae07493818958c5b0
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Alessandro Portale
2019-01-17 01:54:13 +01:00
parent 3fdb5f53e3
commit f5974ad993
15 changed files with 23 additions and 21 deletions

View File

@@ -233,7 +233,7 @@ QVariant DataModel::data(const QModelIndex &index, int role) const
ret += entry.arg(tr("Function:")).arg(func->name().toHtmlEscaped());
ret += entry.arg(tr("File:")).arg(func->file());
if (!func->costItems().isEmpty()) {
const CostItem *firstItem = func->costItems().first();
const CostItem *firstItem = func->costItems().constFirst();
for (int i = 0; i < d->m_data->positions().size(); ++i) {
ret += entry.arg(ParseData::prettyStringForPosition(d->m_data->positions().at(i)))
.arg(firstItem->position(i));

View File

@@ -847,7 +847,8 @@ void CallgrindTool::showParserResults(const ParseData *data)
if (data->events().isEmpty()) {
msg = tr("Parsing finished, no data.");
} else {
const QString costStr = QString::fromLatin1("%1 %2").arg(QString::number(data->totalCost(0)), data->events().first());
const QString costStr = QString::fromLatin1("%1 %2")
.arg(QString::number(data->totalCost(0)), data->events().constFirst());
msg = tr("Parsing finished, total cost of %1 reported.").arg(costStr);
}
} else {

View File

@@ -355,7 +355,7 @@ bool MemcheckErrorFilterProxyModel::filterAcceptsRow(int sourceRow, const QModel
}
}
const QVector< Frame > frames = error.stacks().first().frames();
const QVector<Frame> frames = error.stacks().constFirst().frames();
const int framesToLookAt = qMin(6, frames.size());

View File

@@ -69,8 +69,8 @@ static QString suppressionText(const Error &error)
// try to set some useful name automatically, instead of "insert_name_here"
// we take the last stack frame and append the suppression kind, e.g.:
// QDebug::operator<<(bool) [Memcheck:Cond]
if (!error.stacks().isEmpty() && !error.stacks().first().frames().isEmpty()) {
const Frame frame = error.stacks().first().frames().first();
if (!error.stacks().isEmpty() && !error.stacks().constFirst().frames().isEmpty()) {
const Frame frame = error.stacks().constFirst().frames().constFirst();
QString newName;
if (!frame.functionName().isEmpty())

View File

@@ -167,8 +167,8 @@ ErrorItem::ErrorItem(const ErrorListModel *model, const Error &error)
if (m_error.stacks().count() > 1) {
foreach (const Stack &s, m_error.stacks())
appendChild(new StackItem(s));
} else if (m_error.stacks().first().frames().count() > 1) {
foreach (const Frame &f, m_error.stacks().first().frames())
} else if (m_error.stacks().constFirst().frames().count() > 1) {
foreach (const Frame &f, m_error.stacks().constFirst().frames())
appendChild(new FrameItem(f));
}
}
@@ -211,12 +211,12 @@ QVariant ErrorItem::data(int column, int role) const
case Qt::DisplayRole:
// If and only if there is exactly one frame, we have omitted creating a child item for it
// (see the constructor) and display the function name in the error item instead.
if (m_error.stacks().count() != 1 || m_error.stacks().first().frames().count() != 1
|| m_error.stacks().first().frames().first().functionName().isEmpty()) {
if (m_error.stacks().count() != 1 || m_error.stacks().constFirst().frames().count() != 1
|| m_error.stacks().constFirst().frames().constFirst().functionName().isEmpty()) {
return m_error.what();
}
return ErrorListModel::tr("%1 in function %2")
.arg(m_error.what(), m_error.stacks().first().frames().first().functionName());
.arg(m_error.what(), m_error.stacks().constFirst().frames().constFirst().functionName());
case Qt::ToolTipRole:
return toolTipForFrame(m_model->findRelevantFrame(m_error));
default: