diff options
author | Marc Mutz <[email protected]> | 2025-08-02 07:23:43 +0200 |
---|---|---|
committer | Qt Cherry-pick Bot <[email protected]> | 2025-08-20 12:56:01 +0000 |
commit | 93e65e65423628e868baf24608d4c78e955ae819 (patch) | |
tree | fecde95e68da5b3a38ae59af7e5abb071cb6f31f /src/tools/windeployqt/main.cpp | |
parent | f885f72b572ca33b7abece69655a74d99a6fc3fb (diff) |
QLocale: fix unintended copy [2/2]: QCalendarBackend::dateTimeToString()6.9
Coverity complained that 'text' was copied when it could have been
moved.
This is correct, but not trivial to understand: If, in a ternary
expression, one of the legs is an rvalue and the other is an lvalue,
then the ternary expression is also an rvalue. So the return statement
invokes the QString move constructor.
But, of course, the lvalue isn't being moved from in this case.
Instead, lvalue-to-rvalue conversion materializes a temporary QString
as a copy of lvalue, and _that_ is moved instead. This is what happens
with 'text' and why Coverity complains about a copy.
Note that this is purely due to the use of the ternary: If we write a
normal if, then the lvalue leg returns a local object and we get a
move from it for free. In fact, the structure of the lambda is such
that NRVO should kick in, so neither copy nor move, but direct
construction into the caller-supplied storage of the return object.
To fix, rewrite the code using a normal if statement, taking care to
not break the NRVO the rest of the function so carefully tries to
maintain.
This likely also fixes CID-469957 where Coverity complains that this
lambda's implicit auto return type causes a copy and - incorrectly!
- suggests to explicitly return const QString& (which would return a
reference to a local object).
Amends 1b909695a66500b3cceb0fee668b12a663ed3b8b.
Coverity-Id: 469949
Coverity-Id: 469957
Pick-to: 6.8 6.5
Change-Id: Ia858fd6bddbb51d824b29b0e60d26c18c1c7fb5d
Reviewed-by: Thiago Macieira <[email protected]>
Reviewed-by: Edward Welbourne <[email protected]>
(cherry picked from commit 5b1e49a7e20cdecff5e1a07278ec0dd719337eca)
Reviewed-by: Qt Cherry-pick Bot <[email protected]>
(cherry picked from commit 906a41330813773f258980e4c17ed9985bf0785d)
Diffstat (limited to 'src/tools/windeployqt/main.cpp')
0 files changed, 0 insertions, 0 deletions