Don't std::move() trivally-copyable type; it makes no difference

CodeChecker says:

 std::move of the variable 'parts' of the trivially-copyable type 'QCalendar::YearMonthDay' has no effect; remove std::move()

So don't bother with the move, and remove && from the signature of the
function being called in all four places. Assert that the type *is*
trivially copyable.

Change-Id: I3c07491b4b1dafdf52916e8699561c58c24ee954
Reviewed-by: Marc Mutz <marc.mutz@qt.io>
Reviewed-by: Mårten Nordheim <marten.nordheim@qt.io>
This commit is contained in:
Edward Welbourne 2022-05-23 14:29:09 +02:00
parent 140ca89a3c
commit b6be97f65e

View File

@ -44,8 +44,9 @@ using namespace QtPrivate::DateTimeConstants;
/***************************************************************************** /*****************************************************************************
QDate static helper functions QDate static helper functions
*****************************************************************************/ *****************************************************************************/
static_assert(std::is_trivially_copyable_v<QCalendar::YearMonthDay>);
static inline QDate fixedDate(QCalendar::YearMonthDay &&parts, QCalendar cal) static inline QDate fixedDate(QCalendar::YearMonthDay parts, QCalendar cal)
{ {
if ((parts.year < 0 && !cal.isProleptic()) || (parts.year == 0 && !cal.hasYearZero())) if ((parts.year < 0 && !cal.isProleptic()) || (parts.year == 0 && !cal.hasYearZero()))
return QDate(); return QDate();
@ -54,7 +55,7 @@ static inline QDate fixedDate(QCalendar::YearMonthDay &&parts, QCalendar cal)
return cal.dateFromParts(parts); return cal.dateFromParts(parts);
} }
static inline QDate fixedDate(QCalendar::YearMonthDay &&parts) static inline QDate fixedDate(QCalendar::YearMonthDay parts)
{ {
if (parts.year) { if (parts.year) {
parts.day = qMin(parts.day, QGregorianCalendar::monthLength(parts.month, parts.year)); parts.day = qMin(parts.day, QGregorianCalendar::monthLength(parts.month, parts.year));
@ -1299,7 +1300,7 @@ QDate QDate::addMonths(int nmonths, QCalendar cal) const
count = (++parts.year || cal.hasYearZero()) ? cal.monthsInYear(parts.year) : 0; count = (++parts.year || cal.hasYearZero()) ? cal.monthsInYear(parts.year) : 0;
} }
return fixedDate(std::move(parts), cal); return fixedDate(parts, cal);
} }
/*! /*!
@ -1331,7 +1332,7 @@ QDate QDate::addMonths(int nmonths) const
++parts.year; ++parts.year;
} }
return fixedDate(std::move(parts)); return fixedDate(parts);
} }
/*! /*!
@ -1364,7 +1365,7 @@ QDate QDate::addYears(int nyears, QCalendar cal) const
if (!cal.hasYearZero() && ((old_y > 0) != (parts.year > 0) || !parts.year)) if (!cal.hasYearZero() && ((old_y > 0) != (parts.year > 0) || !parts.year))
parts.year += nyears > 0 ? +1 : -1; parts.year += nyears > 0 ? +1 : -1;
return fixedDate(std::move(parts), cal); return fixedDate(parts, cal);
} }
/*! /*!
@ -1387,7 +1388,7 @@ QDate QDate::addYears(int nyears) const
if ((old_y > 0) != (parts.year > 0) || !parts.year) if ((old_y > 0) != (parts.year > 0) || !parts.year)
parts.year += nyears > 0 ? +1 : -1; parts.year += nyears > 0 ? +1 : -1;
return fixedDate(std::move(parts)); return fixedDate(parts);
} }
/*! /*!