Skip to content

Treatment of unknown bits in operators is inconsistent #363

Closed
@sunfishcode

Description

The complement function's documentation says "the returned set contains all the flags which are not set in self, but which are allowed for this type". So primarily here, the phrase "allowed for this type" is ambiguous; the word "allowed" doesn't appear to be used anywhere else in the documentation, and bitflags in general seems to "allow" bits that aren't defined, with the new from_bits_retain function.

Looking at the code, it appears complement does a from_bits_truncate. Secondarily, I just converted some existing code to bitflags 2.0 and found this behavior surprising. Bitflags allows users to create values with from_bits_retain, and I assumed that applying ! would act like a plain bitwise complement, and had a debugging adventure trying to figure why code that looked like it was setting a flag wasn't actually setting it.

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions