Skip to content

Commit

Permalink
Explicitly delete parseValue<QStringView>()
Browse files Browse the repository at this point in the history
QStringView is a temporary view, not a storage type.
  • Loading branch information
hasselmm committed Oct 7, 2024
1 parent 46561cd commit 1ff8827
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 7 deletions.
1 change: 0 additions & 1 deletion tests/auto/tst_xmlparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -331,7 +331,6 @@ private slots:
QTest::newRow("double:valid") << makeConversionTest<double> (u"4.56", 4.56);
QTest::newRow("longdouble:valid") << makeConversionTest<long double> (u"7.89", 7.89);
QTest::newRow("QString:valid") << makeConversionTest<QString> (u"Hello world", u"Hello world"_s);
QTest::newRow("QStringView:valid") << makeConversionTest<QStringView>(u"Hello world", u"Hello world");
QTest::newRow("QUrl:valid") << makeConversionTest<QUrl> (u"hello:world", "hello:world"_url);
}

Expand Down
8 changes: 2 additions & 6 deletions xml/xmlparser.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,8 @@ std::optional<QString> convert(QStringView text)
return text.toString();
}

template <>
std::optional<QStringView> convert(QStringView text)
{
return text;
}
template <> // QStringView is a temporary view, not a storage type
std::optional<QStringView> convert(QStringView text) = delete;

template <>
std::optional<QUrl> convert(QStringView text)
Expand Down Expand Up @@ -179,7 +176,6 @@ template void ParserBase::parseValue(QStringView, const std::function<void(float
template void ParserBase::parseValue(QStringView, const std::function<void(double)> &);
template void ParserBase::parseValue(QStringView, const std::function<void(long double)> &);
template void ParserBase::parseValue(QStringView, const std::function<void(QString)> &);
template void ParserBase::parseValue(QStringView, const std::function<void(QStringView)> &);
template void ParserBase::parseValue(QStringView, const std::function<void(QUrl)> &);

QString ParserBase::stateName(const QMetaEnum &metaEnum, int value)
Expand Down
3 changes: 3 additions & 0 deletions xml/xmlparser.h
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,9 @@ class ParserBase : public QObject
QXmlStreamReader *const m_xml;
};

template <> // QStringView is not a storage type, it's a temporary view
void ParserBase::parseValue(QStringView text, const std::function<void(QStringView)> &store) = delete;

template <typename StateEnum>
class Parser : public ParserBase
{
Expand Down

0 comments on commit 1ff8827

Please sign in to comment.