Open randomnetcat opened 1 year ago
I don't think there are any integer types with width 1; [implimits] doesn't allow that.
Sorry, which part of [implimits] prohibits such a type? It isn't immediately obvious to me.
https://eel.is/c++draft/basic.fundamental#4.sentence-1 specifies the minimum width to be 8.
I don't see a way to read that as applying to extended integer types.
An extended integer type is an integer type. So it applies. Unless you can point to where that restriction is lifted.
Sorry, which part of [implimits] prohibits such a type? It isn't immediately obvious to me.
Sorry, it's in [basic.fundamental], as @JohelEGP has pointed out.
I don't see a way to read that as applying to extended integer types.
https://eel.is/c++draft/basic.fundamental#4.sentence-1 applies to "signed integer type", which is defined at https://eel.is/c++draft/basic.fundamental#def:type,signed_integer and includes extended signed integer types.
I think that sentence should read "standard signed integer type". Otherwise, we couldn't have extended integer types at all (because the referenced table is exhaustive).
[conv.rank] doesn't help either. Looks like we don't exclude "small" extended integer types. I wonder if we should.
A related question is whether an "int" bit-field of width 1 can faithfully store a "bool" value. [class.bit] p4 doesn't read to me like it could.
Isn't that because it falls out from other rules?
Initializing a non-bool
bit-field from a value of bool
stores 0
or 1
.
But a signed bit-field with width 1 can store the values 0 and -1 only. So, what do we do with the bool
1?
Ah, I see. So if it doesn't fall out from other rules, it would be UB by omission. Maybe you can tag someone who's trying to document or get rid of UB in the standard.
Full name of submitter: Janet Cobb
Reference (section label): [conv.integral]
Issue description:
A signed integer type of width 1 has possible values -1 to 0 per [basic.fundamental].
[conv.integral] states that:
Converting
true
to a width-1 signed integer type therefore should result in the value 1, which is not representable in the target type. This likely results in undefined behavior per [expr.pre]/4.Suggested resolution (explicitly define the behavior):
This would result in
false
being converted to0
andtrue
being converted to-1
.Alternative resolution (explicitly note the behavior is undefined):