09-01-2025, 08:43 AM
Rule 7.0.6 provides the following amplification for assigning numerical types:
2. The source and target shall have types of the same type category, signedness, the source size
shall be smaller than the target size, and the source shall be an id-expression;
Question: why must the source be an "id-expression"?
Consider this example:
This is inconsistent. The fact that we are using a member-expression instead of an id-expression does not have any impact on how the conversion is made, it's equally safe.
Would it make sense to remove the "id-expression" part of the rule? Otherwise, can you elaborate on why is it needed, what problems does it guard against?
Thanks!
2. The source and target shall have types of the same type category, signedness, the source size
shall be smaller than the target size, and the source shall be an id-expression;
Question: why must the source be an "id-expression"?
Consider this example:
Code:
struct Foo
{
float bar;
};
float a;
Foo f;
double d1 = a; // Compliant, since it's an id-expression
double d2 = f.bar; // Non-compliant, since it's NOT an id-expression (it's a member-expression)
This is inconsistent. The fact that we are using a member-expression instead of an id-expression does not have any impact on how the conversion is made, it's equally safe.
Would it make sense to remove the "id-expression" part of the rule? Otherwise, can you elaborate on why is it needed, what problems does it guard against?
Thanks!