[Development] It could be a little bug

Jiergir Ogoerg f35f22fan at gmail.com
Fri Nov 1 23:49:22 CET 2013


Yeah, enums are not meant for bitwise operations, the author could
hand-code the
values of the enum to make them usable for bitwise comparison - but
he didn't..

Anyway who's the hero of the day (and is a contributor) to commit a fix for
this bug?

I for one would like to leave it as is for other people in the future to
waste their
time discussing the wacky behaviour of the function, it's fun.



On Sat, Nov 2, 2013 at 12:40 AM, Nicolás Alvarez
<nicolas.alvarez at gmail.com>wrote:

> 2013/11/1 Marc Mutz <marc.mutz at kdab.com>:
> > 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.
>
> This isn't a QFlags-like bitfield though, since the enum values are
> not different bits. EmptyTable | UnknownSystemComposeDir ==
> MissingComposeFile, which makes no sense; clearly it's not intended to
> be used that way.
>
> --
> Nicolás
> _______________________________________________
> Development mailing list
> Development at qt-project.org
> http://lists.qt-project.org/mailman/listinfo/development
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.qt-project.org/pipermail/development/attachments/20131102/3098d0f7/attachment.html>


More information about the Development mailing list