-
Notifications
You must be signed in to change notification settings - Fork 17.9k
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
cmd/compile: Incorrect conversion to string #13793
Comments
I think the problem is that const A = 0xfffffffffffffffff is not an integer constant (it's an untyped constant) nor can it be implicitly converted to any predeclared Go integer type. Then the specs part "x is an integer constant ..." does not apply. |
This may be a bug in gccgo, not in gc. |
An "integer constant" is not limited to a predeclared Go integer type. There is no limit to the size of an integer constant. I think gccgo is technically correct and gc is technically wrong. gccgo actually has some code to specifically handle this case. |
The spec doesn't say the argument must be an integer constant (or that is must be representable as an int as the error message appears to suggest) - it just requires an (arbitrary) integer value. It says that values outside the Unicode code point range are converted to 0xfffd which is what should happen here. I believe cmd/compile is incorrect; it should accept this code w/o error. FWIW, gotype also accepts this code (and - like gccgo - has code to handle this case specifically). It should be ok to fix cmd/compile as it will not restrict the set of accepted programs (and thus is not an error that we must keep for backward-compatibility). |
In the following program:
The compiler issues error message
overflow in int -> string
.Form the Go Spec https://golang.org/ref/spec#Conversions
...
...
According to the above, the conversion should succeed, with the resulting string containing the UTF-8 encoding of
0xfffd
.gccgo
does not issue an error and behaves as in the spec.The text was updated successfully, but these errors were encountered: