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

Qt combines values from unrelated enum types

XMLWordPrintable

    • Icon: Bug Bug
    • Resolution: Done
    • Icon: P3: Somewhat important P3: Somewhat important
    • None
    • 5.15, 6.0.0
    • Core: Other
    • None

      Combining values from unrelated enumeration types raises static analyzer warnings, e.g. for code

      QPainter p(this);
      p.drawText(textRect, Qt::TextWordWrap|Qt::AlignVCenter, text); 

      Qt::TextWordWrap is a Qt::TextFlag, while Qt::AlignVCenter is a Qt::AlignmentFlag value. QPainter::drawText takes an int for the flags. QPen enums have related problems (Qt::PenStyle, Qt::PenCapStyle, and Qt::PenJoinStyle are designed so that they can be merged).

      While explicitly casting the values to (u)int pacifies the analyzer, we should perhaps implement operators that allow combining values from those particular enums type-safely.

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

            vhilshei Volker Hilsheimer
            vhilshei Volker Hilsheimer
            Votes:
            0 Vote for this issue
            Watchers:
            5 Start watching this issue

              Created:
              Updated:
              Resolved:

                There are no open Gerrit changes