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

QAccessible::Role enum has valid range [0, 65535] instead of full int range

    XMLWordPrintable

Details

    • Bug
    • Resolution: Unresolved
    • P2: Important
    • None
    • 6.6.0 Beta4
    • None

    Description

      The QAccessible::Role enum is declared as

          enum Role {
              NoRole         = 0x00000000,
      [...]
              UserRole       = 0x0000ffff
          }; 

      QAccessible::UserRole is documented as

      The first value to be used for user defined roles.

      which, as far as I understand, means that we should be able to do something like

      static constexpr QAccessible::Role ValueRole = static_cast<QAccessible::Role>(QAccessible::UserRole + 1);
      

      to define a custom role. But this doesn't compile with Clang 16:

      error: integer value 65536 is outside the valid range of values [0, 65535] for this enumeration type [-Wenum-constexpr-conversion]
      static constexpr QAccessible::Role ValueRole = static_cast<QAccessible::Role> (QAccessible::UserRole + 1);
                                                     ^

      Clang is correct because this cast is undefined behavior.

       

      Minimal example:

      #include <QAccessible>
      
      static constexpr QAccessible::Role ValueRole = static_cast<QAccessible::Role>(QAccessible::UserRole + 1);
      

      I have compiled this with

      clang++-16.0 -isystem /usr/include/qt5 -isystem /usr/include/qt5/QtGui -std=gnu++20 main.cpp
      

       

      A possible fix would be to fix the type of the enum, e.g.

      enum Role : int {
          NoRole = 0x00000000,
      [...]
          UserRole = 0x0000ffff
      };

      Attachments

        For Gerrit Dashboard: QTBUG-117517
        # Subject Branch Project Status CR V

        Activity

          People

            qt.team.quick.subscriptions Qt Quick and Widgets Team
            ikloecker Ingo Klöcker
            Votes:
            0 Vote for this issue
            Watchers:
            6 Start watching this issue

            Dates

              Created:
              Updated:

              Gerrit Reviews

                There is 1 open Gerrit change