Skip to content
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

compilers don't complain about out-of-range characters #840

Closed
griesemer opened this issue Jun 4, 2010 · 2 comments
Closed

compilers don't complain about out-of-range characters #840

griesemer opened this issue Jun 4, 2010 · 2 comments

Comments

@griesemer
Copy link
Contributor

According to the spec, out-of-range characters in character literals are illegal - it is
not explicit about what should happen when there are 
out-of-range characters in strings. For the following program:

package main

func main() {
    // println('\777')  // this character is out of range
    // These characters/strings should get out of range errors as well:
    println('\U0010FFFF', 0x0010FFFF)
    println('\U00110000', 0x00110000)  // ERROR 'ilegal'
    println([]int("\U0010FFFF")[0], 0x0010FFFF)
    println([]int("\U00110000")[0], 0xFFFD)  // ERROR 'illegal'
}

the output is as follows:

6g bug286.go && 6l bug286.6 && 6.out
1114111 1114111
1114112 1114112
1114111 1114111
65533 65533

Observations:
1) 6g correctly complains about '\777' being out of range
2) Since '\777' is illegal, '\U00110000' should be illegal as well, however, 6g
interprets it as the integer value 0x00110000
3) The string "\U00110000" is accepted, but the illegal code point is
converted to 0xFFFD - it be should illegal
4) gccgo accepts complains in one case but not the other.
5) One could argue that none of the character literal escapes should be illegal since
they just represent integer values. However, that only 
makes things more complicated, and at the moment 6g appears to be doing the opposite.
@rsc
Copy link
Contributor

rsc commented Jun 9, 2010

Comment 1:

will fix as part of upcoming compiler changes

Status changed to Started.

@rsc
Copy link
Contributor

rsc commented Jun 9, 2010

Comment 2:

This issue was closed by revision 565b5dc.

Status changed to Fixed.

@golang golang locked and limited conversation to collaborators Jun 24, 2016
@rsc rsc unassigned robpike Jun 22, 2022
This issue was closed.
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

4 participants