Uploaded image for project: 'Qt'
  1. Qt
  2. QTBUG-85880

QByteArrayView comparison operators should be hidden friends

    XMLWordPrintable

Details

    • Bug
    • Resolution: Done
    • Not Evaluated
    • None
    • 6.0.0 Beta1
    • None
    • All
    • 883f2dd81f8d85d52130aece540cdf9efa3d0069 (qt/qtbase/dev)

    Description

      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;
      }
      

      Attachments

        Issue Links

          No reviews matched the request. Check your Options in the drop-down menu of this sections header.

          Activity

            People

              sonakur Sona Kurazyan
              bubke Marco Bubke
              Votes:
              0 Vote for this issue
              Watchers:
              2 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved:

                Gerrit Reviews

                  There are no open Gerrit changes