path: root/src/corelib/tools/qtimeline.cpp
diff options
authorGiuseppe D'Angelo <>2021-05-02 03:06:18 +0200
committerGiuseppe D'Angelo <>2021-06-23 03:14:09 +0200
commit631a0cc45cbe70940746cd944d325d7d3bab8c15 (patch)
tree90b375bac817f1999a44f3c37feb193a99ead081 /src/corelib/tools/qtimeline.cpp
parenta20a4240668faa0e6c961b90266918628f9f5484 (diff)
This commit adds an opt-in mechanism to kill type-unsafe functions and implicit conversions of QFlags, therefore removing an entire category of bugs that QFlags itself is supposed to protect against: QFlags<E> f; f == 3.14; // OK; f->int, int->double, then operator==(double,double) f & UnrelatedEnum; // OK if of unscoped enum, calls operator&(int) f &= 123; // calls QFlags::operator&=(int) int i = f * 42; // f->int, then operator*(int, int) Thankfully, operator+ and operator- had already been deleted. By defining QT_TYPESAFE_FLAGS one: * disables operators taking (u)int, forcing the usage of an enumeration or another QFlags object; * turns the implicit conversions towards integers/bool in explicit (one can always use fromInt/toInt instead); * adds a convenience set of (in)equality operators against literal 0, in order to keep code like `(flag & bit) == 0` compile. This set can't be added normally otherwise it would add ambiguity; * adds the unary operator~(Enum), turning it into a flag. This is a source incompatible change, in general, so it's opt-in. This is a Qt-internal macro at this point. It can't be offered to users yet because we need to fix some public API flaws first: in some places (e.g. QPainter::drawText) we ask users to do type-unsafe manipulation of flags. A user enabling the macro wouldn't be able to properly use the functions in question. This macro will be enabled in a follow-up commit. Change-Id: I796f2256b446bafc12cdcbaf7de417d12bd3619e Reviewed-by: Andrei Golubev <> Reviewed-by: Edward Welbourne <> Reviewed-by: Thiago Macieira <>
Diffstat (limited to 'src/corelib/tools/qtimeline.cpp')
0 files changed, 0 insertions, 0 deletions