[Interest] Q_FOREACH creating copy , was (no subject)

Giuseppe D'Angelo dangelog at gmail.com
Tue Jun 30 22:48:56 CEST 2015


On Tue, Jun 30, 2015 at 9:55 PM, Prav <pr12og2 at programist.ru> wrote:
>> Adding a new macro is overruled. Either you modify foreach to work like you
>> want or we leave things as is.
> Giuseppe D'Angelo is not happy with possibility of foreach change ...

It's not a matter of "being happy". It's a matter that there are 100+M
lines of code out there written using Qt, which are relying on the
documented, working and (more or less) reasonable assumption that
foreach makes a copy of the container it iterates upon. Are you going
to analyze every occurence of foreach and think if it is safe to
remove the copy it does? Otherwise, such a change can't land.

Like here and in similar patches by Sérgio and Marc:

https://codereview.qt-project.org/#/c/115389/1/src/widgets/accessible/complexwidgets.cpp

Writing a library is a difficult job. Once you set a behaviour,
changing it is going to break some user code. You are talking about
deliberately breaking thousands of applications without any stringent
need to do so, which can't be allowed.

(If you're in the mood of experimenting, you could write a clang
plugin which checks whether a container gets ever modified from the
body of a foreach over it, and report the think to the developer as a
"possible" optimization hint.)

Cheers,
-- 
Giuseppe D'Angelo



More information about the Interest mailing list