[Development] It could be a little bug
Marc Mutz
marc.mutz at kdab.com
Fri Nov 1 15:35:50 CET 2013
On Tuesday, October 29, 2013 01:21:08 Jiergir Ogoerg wrote:
> Hi,
> There's an enum:
>
> //==> code
> enum TableState
> {
> UnsupportedLocale,
> EmptyTable,
> UnknownSystemComposeDir,
> MissingComposeFile,
> NoErrors
> };
> //<== code
>
> and this:
>
> //==> code
> bool cleanState() const { return ((m_state & NoErrors) == NoErrors); }
> //<== code
>
> Shouldn't the latter be ?:
> //==> code
> bool cleanState() const { return (m_state == NoErrors); }
> //<== code
>
> Found at
> QTSRC/qtbase/src/plugins/platforminputcontexts/compose/generator/qtablegene
> rator.h
According to the standard, they are equivalent, since reading a value from an
enum object that does have one of the declared enum values results in undefined
behaviour. That said, we're violating that in many places in Qt, e.g. in
QFlags, so it might be that the code in question also abuses m_state that way.
in that case, the existing code would be more robust, but faces the compiler
optimising away the & NoErrors due to the reason mentioned above.
The correct fix is to check if m_state takes values not in TableState values
and if so, change its type to int or uint, otherwise, apply your suggestion.
HTH,
Marc
Thanks,
Marc
More information about the Development
mailing list