summaryrefslogtreecommitdiffstats
path: root/cmake/visionos
diff options
context:
space:
mode:
authorMarc Mutz <marc.mutz@qt.io>2025-08-02 07:23:43 +0200
committerMarc Mutz <marc.mutz@qt.io>2025-08-19 22:47:30 +0000
commit5b1e49a7e20cdecff5e1a07278ec0dd719337eca (patch)
treea5951d3fd9fcd88fa45be141eaaf9d2cb96ca1a3 /cmake/visionos
parentcd96362492375c50a9d0614b829c51eb6597d713 (diff)
QLocale: fix unintended copy [2/2]: QCalendarBackend::dateTimeToString()HEADdev
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.10 6.9 6.8 6.5 Change-Id: Ia858fd6bddbb51d824b29b0e60d26c18c1c7fb5d Reviewed-by: Thiago Macieira <thiago.macieira@intel.com> Reviewed-by: Edward Welbourne <edward.welbourne@qt.io>
Diffstat (limited to 'cmake/visionos')
0 files changed, 0 insertions, 0 deletions