Port QVersionNumber to QSpan

The new ctor could replace all existing ones. However, keep the QList
ctors to participate in implicit sharing, but mark them as weak
overloads in order to break the ambiguity for arguments that convert
to both QList and QSpan. Also keep the initalizer_list ctor because
it's implicit, and should be.

[ChangeLog][Potentially Source-Incompatible Changes] We have begun to
port APIs to QSpan, replacing overload sets of concrete container
classes. This breaks code that relied on concrete container class
overloads and passed types that implicitly convert to such a
container, but not to QSpan. The backwards-compatible fix is to make
the conversion explicit.

[ChangeLog][QtCore][QVersionNumber] Added construction from QSpan,
replacing the QVarLengthArray constructor.

Fixes: QTBUG-121480
Change-Id: I9be173d0471872ddc449c876465c6a01abc49ff4
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
This commit is contained in:
Marc Mutz 2024-01-24 10:15:28 +01:00
parent 063e31209b
commit 3afcfbc400
2 changed files with 13 additions and 8 deletions

View File

@ -81,10 +81,13 @@ QT_IMPL_METATYPE_EXTERN(QVersionNumber)
*/
/*!
\fn template <qsizetype N> QVersionNumber::QVersionNumber(const QVarLengthArray<int, N> &seg)
\since 6.4
\fn QVersionNumber::QVersionNumber(QSpan<const int> args)
\since 6.8
Constructs a version number from the list of numbers contained in \a seg.
Constructs a version number from the span specified by \a args.
\note In Qt versions prior to 6.8, QVersionNumber could only be constructed
from QList, QVarLenthArray or std::initializer_list.
*/
/*!

View File

@ -10,6 +10,7 @@
#include <QtCore/qlist.h>
#include <QtCore/qmetatype.h>
#include <QtCore/qnamespace.h>
#include <QtCore/qspan.h>
#include <QtCore/qstring.h>
#include <QtCore/qtypeinfo.h>
#if !defined(QT_LEAN_HEADERS) || QT_LEAN_HEADERS < 2
@ -113,7 +114,7 @@ class QVersionNumber
Q_CORE_EXPORT void setListData(QList<int> &&seg);
explicit SegmentStorage(std::initializer_list<int> args)
explicit SegmentStorage(QSpan<const int> args)
: SegmentStorage(args.begin(), args.end()) {}
explicit SegmentStorage(const int *first, const int *last)
@ -256,19 +257,20 @@ public:
inline QVersionNumber() noexcept
: m_segments()
{}
Q_WEAK_OVERLOAD
inline explicit QVersionNumber(const QList<int> &seg) : m_segments(seg) { }
// compiler-generated copy/move ctor/assignment operators and the destructor are ok
Q_WEAK_OVERLOAD
explicit QVersionNumber(QList<int> &&seg) : m_segments(std::move(seg)) { }
inline QVersionNumber(std::initializer_list<int> args)
: m_segments(args)
: m_segments(QSpan{args})
{}
template <qsizetype N>
explicit QVersionNumber(const QVarLengthArray<int, N> &sec)
: m_segments(sec.begin(), sec.end())
explicit QVersionNumber(QSpan<const int> args)
: m_segments(args)
{}
inline explicit QVersionNumber(int maj)