Skip to content

Commit

Permalink
QFlags::testFlag: code tidies
Browse files Browse the repository at this point in the history
If the condition Int(flag) != 0 is false, it means that flag == 0.
So just check i against 0, which is more in line with what testFlag
behavior is documented to do.

Change-Id: Ia75fa07eee65e67a769fda7c020bf17ada77e9a3
Reviewed-by: Edward Welbourne <[email protected]>
Reviewed-by: Thiago Macieira <[email protected]>
  • Loading branch information
dangelog committed May 13, 2021
1 parent 2378089 commit 81bb764
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion src/corelib/global/qflags.h
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ class QFlags

constexpr inline bool operator!() const noexcept { return !i; }

constexpr inline bool testFlag(Enum flag) const noexcept { return (i & Int(flag)) == Int(flag) && (Int(flag) != 0 || i == Int(flag) ); }
constexpr inline bool testFlag(Enum flag) const noexcept { return (i & Int(flag)) == Int(flag) && (Int(flag) != 0 || i == Int(0) ); }
constexpr inline QFlags &setFlag(Enum flag, bool on = true) noexcept
{
return on ? (*this |= flag) : (*this &= ~QFlags(flag));
Expand Down

0 comments on commit 81bb764

Please sign in to comment.