New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[bitmask.types] Potential undefined behavior in operator~ #1788
Comments
@zygoloid , is this editorial? |
This is basically the same issue that I reported about And it's definitely not editorial. |
@tkoeppe : Which LWG issue number? |
@jensmaurer: LWG 2950. It looks like it's not mentioned there, though I'm sure I've brought both |
@jensmaurer: See "std::byte operations are hard to use correctly" on the lib reflector. |
Even though it's part of the normative text, I had assumed that it was an editorial issue because what the text does is offer a suggestion on how to write a bitmask type. After all, it uses can instead of shall in the introductory line (bitmask.types/2). So does the previous paragraph. If it actually meant that we can only choose among those (enumerated type, integer type, or Should I submit a defect report based on the OP? |
[bitmask.types] is part of [description], which is labeled informative. Also, the resolution of Core issue 2338 in P0818R0 should obviate the problem. |
Ah, that's where I had mentioned this problem. |
Ah, I lost sight of the big picture.
Does CWG has a more actively updated issues repository like LWG does? I can't find one. |
Wording relative to n4700.
[bitmask.types] specifies that a bitmask type's
operator~
can be written asfor
The suggested
operator~
results in undefined behavior ifsizeof(int_type) < sizeof(int)
becausestatic_cast<int_type>(X)
has to be promoted toint
before evaluating~
, and the outterstatic_cast<bitmask>
would result in undefined behavior because its operand is not within the range of the enumeration values as explained in [expr.static.cast]/10.My suggested solution is wrapping the
~
and its operand instatic_cast<int_type>
as follows:Greetings,
Johel
The text was updated successfully, but these errors were encountered: