QAnyStringView: fix broken implicit conversion from QStringBuilder

Need to use QConcatenable<>::ConvertTo for SFINAE, the forwarded type
alias in QStringBuilder itself doesn't work.

[ChangeLog][QtCore][QAnyStringView/QStringBuilder] Implicit conversion
from QStringBuilder to QAnyStringView now works as advertised.

Pick-to: 6.2
Fixes: QTBUG-98138
Change-Id: I1c300675cf43b13017bc56398ae5d8c1c51e64fe
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Fabian Kosmale <fabian.kosmale@qt.io>
This commit is contained in:
Marc Mutz 2021-11-16 14:59:30 +01:00
parent 8283df4d8c
commit b7f4041669
3 changed files with 21 additions and 2 deletions

View File

@ -50,6 +50,7 @@
QT_BEGIN_NAMESPACE
template <typename, typename> class QStringBuilder;
template <typename> struct QConcatenable;
class QAnyStringView
{
@ -163,7 +164,7 @@ public:
// defined in qstringbuilder.h
template <typename A, typename B>
inline QAnyStringView(const QStringBuilder<A, B> &expr,
typename QStringBuilder<A, B>::ConvertTo &&capacity = {});
typename QConcatenable<QStringBuilder<A, B>>::ConvertTo &&capacity = {});
template <typename Container, if_compatible_container<Container> = true>
constexpr QAnyStringView(const Container &c) noexcept

View File

@ -468,7 +468,7 @@ QString &operator+=(QString &a, const QStringBuilder<A, B> &b)
template <typename A, typename B>
QAnyStringView::QAnyStringView(const QStringBuilder<A, B> &expr,
typename QStringBuilder<A, B>::ConvertTo &&capacity)
typename QConcatenable<QStringBuilder<A, B>>::ConvertTo &&capacity)
: QAnyStringView(capacity = expr) {}
QT_END_NAMESPACE

View File

@ -30,6 +30,7 @@
#include <QChar>
#include <QList>
#include <QString>
#include <QStringBuilder>
#include <QVarLengthArray>
#include <QTest>
@ -230,6 +231,12 @@ static_assert(CanConvert<std::array<wchar_t, 123>> == CanConvertFromWCharT);
static_assert(!CanConvert<std::deque<wchar_t>>);
static_assert(!CanConvert<std::list<wchar_t>>);
//
// QStringBuilder
//
static_assert(CanConvert<QStringBuilder<QString, QString>>);
class tst_QAnyStringView : public QObject
{
@ -303,9 +310,13 @@ private Q_SLOTS:
void fromChar16TContainers() const { fromContainers<char16_t>(); }
void fromWCharTContainers() const { ONLY_WIN(fromContainers<wchar_t>()); }
void fromQStringBuilder_QString_QString() const { fromQStringBuilder(u"1"_qs % u"2"_qs, u"12"); }
void comparison();
private:
template <typename StringBuilder>
void fromQStringBuilder(StringBuilder &&sb, QStringView expected) const;
template <typename Char>
void fromArray() const;
template <typename String>
@ -419,6 +430,13 @@ void tst_QAnyStringView::basics() const
QVERIFY(!(sv2 != sv1));
}
template <typename StringBuilder>
void tst_QAnyStringView::fromQStringBuilder(StringBuilder &&sb, QStringView expected) const
{
auto toAnyStringView = [](QAnyStringView sv) { return sv; };
QCOMPARE(toAnyStringView(std::forward<StringBuilder>(sb)), expected);
}
template <typename Char>
void tst_QAnyStringView::fromArray() const
{