diff options
author | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-03 18:32:14 +0900 |
---|---|---|
committer | Kitsune Ral <Kitsune-Ral@users.sf.net> | 2018-04-03 18:32:14 +0900 |
commit | d76b2fbe30a503009d33c4df06848d7356fc39a6 (patch) | |
tree | f2c2476ed6f89cab6c4d5b3b8247fdccc041c865 /lib/connection.cpp | |
parent | d9f09be82b716c5261a36feb6006c4978d989d9e (diff) | |
download | libquotient-d76b2fbe30a503009d33c4df06848d7356fc39a6.tar.gz libquotient-d76b2fbe30a503009d33c4df06848d7356fc39a6.zip |
DirectChatEvent: be careful with range-for over temporaries
...because temporaries returned by temporaries tend to disappear before you enter the loop body (see the bottom of http://en.cppreference.com/w/cpp/language/range-for#Explanation).
Diffstat (limited to 'lib/connection.cpp')
-rw-r--r-- | lib/connection.cpp | 10 |
1 files changed, 2 insertions, 8 deletions
diff --git a/lib/connection.cpp b/lib/connection.cpp index 9d0a34f3..71ada8f7 100644 --- a/lib/connection.cpp +++ b/lib/connection.cpp @@ -281,8 +281,7 @@ void Connection::sync(int timeout) void Connection::onSyncSuccess(SyncData &&data) { d->data->setLastEvent(data.nextBatch()); - auto allRoomData = data.takeRoomData(); - for (auto&& roomData: allRoomData) + for (auto&& roomData: data.takeRoomData()) { const auto forgetIdx = d->roomIdsToForget.indexOf(roomData.roomId); if (forgetIdx != -1) @@ -303,12 +302,7 @@ void Connection::onSyncSuccess(SyncData &&data) { r->updateData(std::move(roomData)); QCoreApplication::processEvents(); } - // `for (auto&& accountEvent: data.takeAccountData())` doesn't work well - // with Clang on FreeBSD in Release configuration; it seems that - // the lifetime of the returned rvalue does not extend (violating the - // standard) and accountEvent refers to garbage in the loop body as a result. - auto allAccountData = data.takeAccountData(); - for (auto&& accountEvent: allAccountData) + for (auto&& accountEvent: data.takeAccountData()) { if (accountEvent->type() == EventType::DirectChat) { |