-
Notifications
You must be signed in to change notification settings - Fork 771
[expr.add] p4 lacks to specify the case when the expression J has an unscoped enumeration type CWG1642 #5199
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
Comments
[expr.add]/1: The usual arithmetic conversions are performed for operands of arithmetic or enumeration type. |
All cases defined in [expr.arith.conv] do not mention the operand with pointer type.
Presumably, the usual arithmetic conversions are only performed when two operands are both of arithmetic or enumeration type. enum A{
a = 0;
};
int arr[2];
int* ptr = arr;
ptr + A::a; |
Specification of the usual arithmetic conversions fails if we allow pointer operands to get there. For pointer operands we'd be forced to execute the very last - unconditional - entry in the sub-list (1.5.5 in the screenshot above) and convert the pointer to some integer type. This, of course, does not make a shred of sense. If the original intent was to perform integral promotions (for enums and |
It is not clear what you mean by your side note about the bullets being "all false". The very last bullet in this list does not have an "if" condition associated with it. So, it can't be "true" or "false". It is unconditional. If you get to that bullet in the list you have to follow it. Which implies that if pointers get here, they shall be converted to unsigned integer type. This, of course, is definitely not the intent. Clearly, usual arithmetic conversions are not supposed to be applied when one operand is a pointer. |
It does not make sense that this bullet would be performed on an operand of pointer type. The exact issue is that [expr.add] p1 and p2 have listed the permitted types of operands for addition and subtraction, respectively, which comprises unscoped enumeration type, but the usual arithmetic conversions obviously does not apply to the case where one operand has pointer type and the other has unscoped enumeration type, and [expr.add] p4 only defines the case where one operand has a pointer type and the other has an integral type. Obviously, unscoped enumeration type is not an integral type. From the context of the definition of usual arithmetic conversion, it is only performed for the case where both operands of a binary operator are of arithmetic or enumeration type. So, it may be an improvement if we change the following sentence
to
For all binary operators in [expr] that expect usual arithmetic conversions to perform on their operands. For the subject of this issue. We should augment [expr.add] p4 to make integer promotion conversion first apply to the operand that is of the unscoped enumeration or integral type. |
Yes, that's exactly my point. It makes no sense to stuff Note that the problem exists with
Precisely. There's no reason to modify the definition of usual arithmetic conversions to make them handle pointer operand. They have never been intended for that purpose. All that needs to be done is apply integral promotions early in [expr.add]. |
It should note that adding the restriction regarding what situation the usual arithmetic conversion can apply is also a key point.
This can emphasize the scope of the application of the usual arithmetic conversion. |
Fixed by CWG1642 |
[expr.add] p4 only specifies the calculation process for the case when J has an integral type and P has a pointer type
Since we admit that J can also have an unscoped enumeration type in [expr.add] p1 and [expr.add] p2. And, I think the usual arithmetic conversion is not applied to the case when J has an unscoped enumeration type and P has a pointer type. Should we augment [expr.add] p4 to be that?
The text was updated successfully, but these errors were encountered: