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

Fix enum/enum arithmetic in Qt

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Fixed
    • Icon: P2: Important P2: Important
    • 5.15, 6.2.5, 6.3.1, 6.4.0 Beta1
    • 5.15.8, 6.2.4, 6.3.0 Beta2
    • Core: Other
    • None
    • 8
    • Team Two Foundation Sprint 50, Team Two Foundation Sprint 51, Team Two Foundation Sprint 52, Team B Foundation Sprint 53, Team B Foundation Sprint 55, Team B Foundation Sprint 56, Team B Foundation Sprint 57, Team B Foundation Sprint 58, Team B Foundation Sprint 59

      In C++, mixed enum-enum-arithmetic is deprecated since C++20. Unfortunately, we use it all over the place in Qt. Most of those cases relate to combining various flags. To future proof Qt, we need to address those.

      Currently, those are (if fixed at all) handled in a rather ad-hoc way. The most prominent example would be QKeyCombination, introducing a new class with a somewhat rich API  (key/keyboardModifiers/toCombined). In most other places, explicit casts to int are used.

       

      While a custom class might be warranted for public API, for internal flag handling this seems to be overkill. However, sprinkling casts or bespoke operator| all over the place is also not ideal. Thus, the idea is to create a new template, QFlagsV2 (name pending), which would have an API similar to QFlags, but supporting 2 or more different enums.

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

            mmutz Marc Mutz
            fabiankosmale Fabian Kosmale
            Vladimir Minenko Vladimir Minenko
            Alex Blasche Alex Blasche
            Votes:
            0 Vote for this issue
            Watchers:
            4 Start watching this issue

              Created:
              Updated:
              Resolved: