refs #937 Resolved clazy warnings: unnecessary detaching of containers.

This commit is contained in:
Mathew Sutcliffe
2017-04-15 01:19:26 +01:00
parent ce1730b453
commit fce1513dae
25 changed files with 108 additions and 63 deletions

View File

@@ -15,6 +15,7 @@
*/
#include "expect.h"
#include "blackmisc/range.h"
#include <QCoreApplication>
#include <QEventLoop>
@@ -81,7 +82,8 @@ void Expect::wait(const SourceLocation& srcloc, int timeout)
{
i->onDone([&](const ExpectUnit* u){ unitsCopy.remove(u); });
}
for (auto i : unitsCopy.toList()) // toList is an easy way to make a temporary copy, needed because init might invalidate iterators
// toList is an easy way to make a temporary copy, needed because init might invalidate iterators
for (auto i : unitsCopy.toList()) // clazy:exclude=container-anti-pattern,range-loop
{
i->init();
}
@@ -90,7 +92,7 @@ void Expect::wait(const SourceLocation& srcloc, int timeout)
timer.setSingleShot(true);
QObject::connect(&timer, &QTimer::timeout, [=, &unitsCopy]{
reportTimeout(srcloc, unitsCopy);
for (auto i : unitsCopy)
for (auto i : BlackMisc::as_const(unitsCopy))
{
i->onDone(nullptr); //paranoia
}

View File

@@ -61,7 +61,7 @@ namespace BlackCoreTest
ConnectGuard &operator+= (const QMetaObject::Connection &conn) { m_conns += conn; return *this; }
//! Disconnect and remove all stored connections.
void cleanup() { for (auto i = m_conns.begin(); i != m_conns.end(); ++i) QObject::disconnect(*i); m_conns.clear(); }
void cleanup() { for (auto i = m_conns.cbegin(); i != m_conns.cend(); ++i) QObject::disconnect(*i); m_conns.clear(); }
//! Copying is only allowed when there are no connections stored.
//! @{