From 3343eeb1fb342c396bcc4855ae20d55e855ef0d8 Mon Sep 17 00:00:00 2001 From: Marc Mutz Date: Tue, 27 Jun 2023 09:14:09 +0200 Subject: [PATCH] tst_QFutureSynchronizer: describe how setFutureAliasingExistingMember() works MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit So no-one 'fixes' the test by pinning synchronizer.futures() into a named variable or collapsing the two lines into one. Both would break the premiss of the test. Amends e8dcbaaaf61ee2164db61e70a5d61d7a5b849371. Change-Id: I7a98c382a7db0bf3ff369dcaf61af0942796d6a3 Reviewed-by: Thiago Macieira Reviewed-by: MÃ¥rten Nordheim (cherry picked from commit 70a7a695fdbaccd042aa4371cbb231ced2d9b499) Reviewed-by: Qt Cherry-pick Bot --- .../thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp b/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp index b2efd6473b6..e198bb931e2 100644 --- a/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp +++ b/tests/auto/corelib/thread/qfuturesynchronizer/tst_qfuturesynchronizer.cpp @@ -45,6 +45,11 @@ void tst_QFutureSynchronizer::setFutureAliasingExistingMember() // WHEN: calling setFuture() with an alias of the QFuture already in `synchronizer`: // for (int i = 0; i < 2; ++i) { + // The next line triggers -Wdangling-reference, but it's a FP because + // of implicit sharing. We cannot keep a copy of synchronizer.futures() + // around to avoid the warning, as the extra copy would cause a detach() + // of m_futures inside setFuture() with the consequence that `f` no longer + // aliases an element in m_futures, which is the goal of this test. const auto &f = synchronizer.futures().constFirst(); synchronizer.setFuture(f); }