CFE fails to report error on inaccurate int->double conversion when demotion is possible. #55736
Labels
area-front-end
Use area-front-end for front end / CFE / kernel format related issues.
cfe-dysfunctionalities
Issues for the CFE not behaving as intended
front-end-missing-error
The "expressions -> numbers" section of the spec says that int->double conversion happens solely based on types, not on the value of the integer literal:
Then, later, it specifies that it is a compile-time error if int->double conversion happens, but the integer can't be represented exactly as a double:
As far as I can tell, the analyzer implements these rules faithfully. But the CFE seems to implement a different set of rules. It looks like the CFE only does int->double conversion when the value i can be represented precisely by an instance of
double
; otherwise it lets the static type of the numeric literal beint
.Usually, this is benign, because the important thing from a spec compliance standpoint is that there is a compile-time error. For example, consider:
The analyzer's error message for this code is:
The integer literal is being used as a double, but can't be represented as a 64-bit double without overflow or loss of precision: '11111111111111111'. Try using the class 'BigInt', or switch to the closest valid double: '11111111111111112'.
Whereas the CFE's error message is:
Error: A value of type 'int' can't be assigned to a variable of type 'double'.
This is not technically the correct reason why the code should be rejected, but since the code is rejected, it's spec compliant.But if the numeric literal occurs in a place where the context is
double
, but a static type ofint
would be valid (e.g. because demotion is possible), then the CFE fails to follow the spec. Consider:The analyzer's error message for this code is the same as before. But the CFE accepts the code without complaint, which is definitely not what the specification says to do.
The text was updated successfully, but these errors were encountered: