diff options
author | Joerg Bornemann <joerg.bornemann@digia.com> | 2014-02-10 17:11:08 +0100 |
---|---|---|
committer | The Qt Project <gerrit-noreply@qt-project.org> | 2014-02-11 13:28:35 +0100 |
commit | cbc6387a2885b17c372d14ceee87c1fba893b97b (patch) | |
tree | 4845d82d6994975d90b46c07001004ebe5844cd7 | |
parent | 5428db88de40378d0419aea40515d98241d733bc (diff) |
support c'tor as second parameter in foreach macro
Passing a constructor as second argument to foreach didn't work when
building with gcc.
For MSVC this already worked as a different foreach implementation is
used.
Change-Id: Id98444c699b4cebc14ea62076c5f7cba33ffb824
Reviewed-by: hjk <hjk121@nokiamail.com>
Reviewed-by: Jędrzej Nowacki <jedrzej.nowacki@digia.com>
-rw-r--r-- | src/corelib/global/qglobal.h | 2 | ||||
-rw-r--r-- | tests/auto/corelib/global/qglobal/tst_qglobal.cpp | 7 |
2 files changed, 8 insertions, 1 deletions
diff --git a/src/corelib/global/qglobal.h b/src/corelib/global/qglobal.h index 30db4e75cf..cd3b0fe71c 100644 --- a/src/corelib/global/qglobal.h +++ b/src/corelib/global/qglobal.h @@ -858,7 +858,7 @@ public: }; #define Q_FOREACH(variable, container) \ -for (QForeachContainer<__typeof__(container)> _container_(container); \ +for (QForeachContainer<__typeof__((container))> _container_((container)); \ !_container_.brk && _container_.i != _container_.e; \ __extension__ ({ ++_container_.brk; ++_container_.i; })) \ for (variable = *_container_.i;; __extension__ ({--_container_.brk; break;})) diff --git a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp index 0d08e912f8..4eb3e4fc98 100644 --- a/tests/auto/corelib/global/qglobal/tst_qglobal.cpp +++ b/tests/auto/corelib/global/qglobal/tst_qglobal.cpp @@ -101,6 +101,13 @@ void tst_QGlobal::for_each() QCOMPARE(i, counter++); } QCOMPARE(counter, list.count()); + + // check whether we can pass a constructor as container argument + counter = 0; + foreach (int i, QList<int>(list)) { + QCOMPARE(i, counter++); + } + QCOMPARE(counter, list.count()); } void tst_QGlobal::qassert() |