-
Bug
-
Resolution: Done
-
Not Evaluated
-
None
-
6.0.0 Beta1
-
None
-
-
883f2dd81f8d85d52130aece540cdf9efa3d0069 (qt/qtbase/dev)
QByteArrayView has quite greedy constructors and operator== is not a hidden friend. If you mix that with other classes like std::string_view you can get easily errors because the compiler does not know which to choose. This can make porting code to Qt6 much harder.
If operator== is a hidden friend one of the arguments has to be a QByteArrayView , so it will not collide with other string classes.
I tried to make a very simple example. The comparison gets ambiguous .
#include <QCoreApplication>
#include <qbytearrayview.h>
#include <string_view>
namespace llvm {
class String
{
public:
using iterator = std::string::iterator;
using const_iterator = iterator;
const char *data() const noexcept;
std::size_t size() const noexcept;
constexpr const_iterator begin() const noexcept;
constexpr const_iterator end() const noexcept;
};
class StringView : public std::string_view
{
public:
using std::string_view::string_view;
template<class String>
StringView(const String &text) : StringView(text.data(), text.size())
{}
};
bool operator==(llvm::StringView, llvm::StringView)
{
return true;
}
} // namespace llvm
int main(int argc, char *argv[])
{
std::string text;
llvm::String text2;
return text == text2;
}
- relates to
-
QTBUG-86481 QAnyStringView comparison operators should be hidden friends
-
- Closed
-
| For Gerrit Dashboard: QTBUG-85880 | ||||||
|---|---|---|---|---|---|---|
| # | Subject | Branch | Project | Status | CR | V |
| 309341,2 | Avoid possible ambiguities with QByteArrayView's comparison operators | dev | qt/qtbase | Status: MERGED | +2 | 0 |