From a1d4c647158f484f02450284a88999df9fec4683 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Mon, 2 Sep 2024 15:55:21 +0200 Subject: [PATCH] Make QDirListing::const_iterator post-increment return void MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit std::weakly_incrementable doesn't require a std::input_iterator's post-increment operator to return anything¹, so don't. ¹ https://eel.is/c++draft/iterator.concepts#iterator.concept.winc-14 The return value of post-increment on objects that model input_iterator is partially-formed (as a copy of an iterator since advanced), so any attempts to use it, apart from assigning a new iterator or destroying it, are undefined, anyway. Found in API-review. Change-Id: If0c07250cec4e48c6e5176cd23864651e8ec3d27 Reviewed-by: Thiago Macieira Reviewed-by: Ahmad Samir (cherry picked from commit fd89fc8c27460e2c11d9e3decc38cf61c186f984) Reviewed-by: Qt Cherry-pick Bot --- src/corelib/io/qdirlisting.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/corelib/io/qdirlisting.h b/src/corelib/io/qdirlisting.h index 9d83411728c..4c6cd3ba952 100644 --- a/src/corelib/io/qdirlisting.h +++ b/src/corelib/io/qdirlisting.h @@ -116,7 +116,7 @@ public: reference operator*() const { return dirEntry; } pointer operator->() const { return &dirEntry; } Q_CORE_EXPORT const_iterator &operator++(); - const_iterator operator++(int) { auto tmp = *this; operator++(); return tmp; }; + void operator++(int) { ++*this; }; // [iterator.concept.winc]/14 not required to return sth private: bool atEnd() const noexcept { return dirEntry.dirListPtr == nullptr; } friend bool operator==(const const_iterator &lhs, sentinel) noexcept { return lhs.atEnd(); }