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

Starship operator not applicable to const QString on Apple

    XMLWordPrintable

Details

    • User Story
    • Resolution: Out of scope
    • Not Evaluated
    • None
    • 6.8.2
    • None
    • macOS

    Description

      It seems that the starship operator cannot be applied to const QString objects when compiling on MacOS.
      I have a small project that I recently moved from C+17 to C+20, introducing where suitable the starship operator (<=>).

      I also ensured that CMakeLists.txt contains both the following lines:

      set(CMAKE_CXX_STANDARD 20)
      set(CMAKE_CXX_STANDARD_REQUIRED ON)

      While the project compiles smoothliy on Linux (gcc 13) and Windows (both MinGW and MSVC), the XCode compiler stops early and shows the following error:

      [ 28%] Building CXX object CMakeFiles/MyApp.dir/MyApp_autogen/mocs_compilation.cpp.o
      /Applications/Xcode-16.2.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/c++
      -DQT_CORE_LIB
      -DQT_GUI_LIB
      -DQT_NO_DEBUG
      -DQT_WIDGETS_LIB
      -I/Users/distiller/project/build
      -I/Users/distiller/project
      -I/Users/distiller/project/build/MyApp_autogen/include
      -isystem /opt/homebrew/opt/qt/lib/QtCore.framework/Headers
      -iframework /opt/homebrew/opt/qt/lib
      -isystem /opt/homebrew/opt/qt/share/qt/mkspecs/macx-clang
      -isystem /opt/homebrew/opt/qt/include
      -isystem /opt/homebrew/opt/qt/lib/QtGui.framework/Headers
      -isystem /opt/homebrew/include
      -isystem /opt/homebrew/opt/qt/lib/QtWidgets.framework/Headers
      -std=gnu++20
      -arch arm64
      -isysroot /Applications/Xcode-16.2.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX15.2.sdk
      -mmacosx-version-min=14.6
      -MD
      -MT CMakeFiles/MyApp.dir/MyApp_autogen/mocs_compilation.cpp.o
      -MF CMakeFiles/MyApp.dir/MyApp_autogen/mocs_compilation.cpp.o.d
      -o CMakeFiles/MyApp.dir/MyApp_autogen/mocs_compilation.cpp.o
      -c /Users/distiller/project/build/MyApp_autogen/mocs_compilation.cpp
      In file included from /Users/distiller/project/build/MyApp_autogen/mocs_compilation.cpp:2:
      In file included from /Users/distiller/project/build/MyApp_autogen/EWIEGA46WW/moc_categoriesmodel.cpp:9:
      In file included from /Users/distiller/project/build/MyApp_autogen/EWIEGA46WW/../../../categoriesmodel.hpp:26:
      /Users/distiller/project/build/MyApp_autogen/EWIEGA46WW/../../../category.hpp:99:42: error: invalid operands to binary expression ('const QString' and 'const QString')
         99 |         return (lhs.getFullDescription() <=> rhs.getFullDescription());
            |                 ~~~~~~~~~~~~~~~~~~~~~~~~ ^   ~~~~~~~~~~~~~~~~~~~~~~~~
      1 error generated.
      make[2]: *** [CMakeFiles/MyApp.dir/MyApp_autogen/mocs_compilation.cpp.o] Error 1
      make[1]: *** [CMakeFiles/MyApp.dir/all] Error 2
      make: *** [all] Error 2
      Exited with code exit status 2
      

      I split the compile command on many lines to improve readability and I would like to pinpoint some important things:

      • the -std=gnu++20 is present;
      • the function getFullDescription() returns a QString const reference since its signature is QString const &getFullDescription() const;.

      I compile for both Linux and Windows on a machine owned by myself, while I rely on an external service (CircleCI) to compile for MacOS.

      I tried downgrading to Xcode-16.1 without any change.

      What I am asking is to understand if this is a bug of the compiler or something to fix in the Qt library when compiled for MacOS.

      Attachments

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

        Activity

          People

            ivan.solovev Ivan Solovev
            flinco Lorenzo Buzzi
            Votes:
            0 Vote for this issue
            Watchers:
            3 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved:

              Gerrit Reviews

                There are no open Gerrit changes