Summary
While refactoring the non-decimal integer literal parsing logic in the lexer, I noticed that gccrs does not enforce the presence of valid digits after a base prefix (0x, 0b, 0o). It silently accepts the empty prefix as a valid literal and evaluates it to 0.
Reproducer
I tried this code:
fn main() {
let _a: u32 = 0x;
let _b: i32 = 0b;
let _c: usize = 0o;
}
Actual behavior
gccrs compiles the above code without emitting any errors. The lexer produces a valid token with the value 0 because the internal string parsing loop naturally terminates, and the empty string is evaluated as 0 by the underlying conversion logic.
Expected behavior
error[E0768]: no valid digits found for number
--> src/main.rs:2:19
|
2 | let _a: u32 = 0x;
| ^^
error[E0768]: no valid digits found for number
--> src/main.rs:3:19
|
3 | let _b: i32 = 0b;
| ^^
error[E0768]: no valid digits found for number
--> src/main.rs:4:21
|
4 | let _c: usize = 0o;
| ^^
For more information about this error, try `rustc --explain E0768`.
error: could not compile `t` (bin "t") due to 3 previous errors
GCC Version
commit-hash: 0c1834c
Summary
While refactoring the non-decimal integer literal parsing logic in the lexer, I noticed that gccrs does not enforce the presence of valid digits after a base prefix (0x, 0b, 0o). It silently accepts the empty prefix as a valid literal and evaluates it to 0.
Reproducer
I tried this code:
Actual behavior
gccrs compiles the above code without emitting any errors. The lexer produces a valid token with the value 0 because the internal string parsing loop naturally terminates, and the empty string is evaluated as 0 by the underlying conversion logic.
Expected behavior
GCC Version
commit-hash: 0c1834c