Use explicit flag values or explicit constructor instead of nullptr
ClosedPublic

Authored by kossebau on May 31 2017, 11:31 PM.

Details

Summary

The constructor of QFlags which was intended to handle literal "0"
as commonly used indicator of no-flags-set has been done with a
trick based on pointer types. Which these days of nullptr existing and
compilers pushing to use that sadly fired back and, instead of
allowing convenient code with commonly understood literal "0" values,
resulted in quite some code using "nullptr" to indicate a QFLags-based
type value with no flags set, which can be puzzling for humans
reading the code.

To improve the code again, instead of "nullptr" are used:

  • enum item representing the 0=no-flag-set value, if existing
  • explicit constructor

Diff Detail

Repository
R236 KWidgetsAddons
Lint
Automatic diff as part of commit; lint not applicable.
Unit
Automatic diff as part of commit; unit tests not applicable.
kossebau created this revision.May 31 2017, 11:31 PM
Restricted Application added a project: Frameworks. · View Herald TranscriptMay 31 2017, 11:31 PM
cfeck added inline comments.Jun 1 2017, 10:56 AM
src/kfontrequester.cpp
187

Does removing the default value mean the flags would be now uninitialized?

kfunk accepted this revision.Jun 1 2017, 11:08 AM
kfunk added a subscriber: kfunk.
kfunk added inline comments.
src/kfontrequester.cpp
187

No, QFontDialog::FontDialogOptions is a QFlags<> which has a default constructor which initializes all members.

This revision is now accepted and ready to land.Jun 1 2017, 11:08 AM
kossebau added inline comments.Jun 1 2017, 11:09 AM
src/kfontrequester.cpp
187

No, the constructor called would be (as before) QFlags::QFlags<QFontDialog::FontDialogOption>(Zero zero = Q_NULLPTR), so still default to 0 internally, so with no flag set.
(cmp. also https://code.woboq.org/qt5/qtbase/src/corelib/global/qflags.h.html#_ZN6QFlagsC1EMNS_7PrivateEi)

cfeck accepted this revision.Jun 1 2017, 11:38 AM
This revision was automatically updated to reflect the committed changes.