Bug 472056 - accessiblevaluelabel.cpp fails to build with Clang 16
Summary: accessiblevaluelabel.cpp fails to build with Clang 16
Status: RESOLVED UPSTREAM
Alias: None
Product: kleopatra
Classification: Applications
Component: general (show other bugs)
Version: git master
Platform: Other All
: NOR normal
Target Milestone: ---
Assignee: Ingo Klöcker
URL:
Keywords:
Depends on:
Blocks:
 
Reported: 2023-07-07 16:47 UTC by Raphael Kubo da Costa
Modified: 2023-09-25 20:43 UTC (History)
5 users (show)

See Also:
Latest Commit:
Version Fixed In:


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Raphael Kubo da Costa 2023-07-07 16:47:17 UTC
See the whole build log here: https://pkg-status.freebsd.org/beefy18/data/main-amd64-default/p12211587418a_see8b0c436d/logs/kleopatra-23.04.2.log

The actual error is

    src/accessibility/accessiblevaluelabel.cpp:21:48: error: integer value 65536 is outside the valid range of values [0, 65535] for the enumeration type 'Role' [-Wenum-constexpr-conversion]
static constexpr QAccessible::Role ValueRole = static_cast<QAccessible::Role>(QAccessible::UserRole + 1);

which comes from Clang 16 defaulting to using C++17 instead of C++14 and throwing a bunch of new errors on code that used to work.
Comment 1 Raphael Kubo da Costa 2023-07-07 17:20:18 UTC
Actually this is unrelated to C++17, it's just Clang 16 being stricter and pointing out invalid code (even if I manually make it build that file in C++14 mode, for example).
Comment 2 Ingo Klöcker 2023-09-17 14:47:07 UTC
QAccessible::UserRole is documented as "The first value to be used for user defined roles.". Hence, we are supposed to use QAccessible::UserRole + n for user defined roles. I'm using QAccessible::UserRole + 1.

Unfortunately, Qt chose 0x0000ffff as value for QAccessible::UserRole, so that all values of the QAccessible::Role enum fit into uint16 and apparently clang 16 chooses uint16 as underlying type (because the "underlying type is an implementation-defined integral type that can represent all enumerator values").

I consider this a bug in Qt. To me, Qt clearly intends QAccessible::Role as a 32-bit enum (apparent from the 32-bit hex notation used for the enum values) and therefore needs to state int (or unsigned int) explicitly as underlying type of QAccessible::Role:
```
enum Role {
        NoRole         = 0x00000000,
        TitleBar       = 0x00000001,
        MenuBar        = 0x00000002,
```
https://code.qt.io/cgit/qt/qtbase.git/tree/src/gui/accessible/qaccessible_base.h

This is related to bug https://bugreports.qt.io/browse/QTBUG-64962 which was closed as invalid without addressing the issue that compilers can choose smaller underlying types than (seemingly) intended by Qt.
Comment 3 Andreas Sturmlechner 2023-09-25 13:04:49 UTC
Who's going to revive that upstream bug then?
Comment 4 Ingo Klöcker 2023-09-25 13:28:02 UTC
It's on my todo list to open an upstream bug for this. The old bug was mainly about int vs. unsigned int.

For now the fix is to patch
enum Role {
to
enum Role : int {
in src/gui/accessible/qaccessible_base.h of qtbase.
Comment 5 Ingo Klöcker 2023-09-25 20:43:34 UTC
Upstream bug report for Qt: https://bugreports.qt.io/browse/QTBUG-117517