Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions gcc/rust/lex/rust-lex.cc
Original file line number Diff line number Diff line change
Expand Up @@ -2150,15 +2150,22 @@ Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,
raw_str += current_char; // x, o, b
skip_input ();

int length = 1;
int length = 2;
bool has_valid_digit = false;

current_char = peek_input ();

length++;

// loop through to add entire number to string
while (is_digit_func (current_char.value) || current_char == '_')
while (true)
{
if (is_digit_func (current_char.value))
{
has_valid_digit = true;
}
else if (current_char != '_')
{
break;
}
length++;

raw_str += current_char;
Expand All @@ -2176,6 +2183,11 @@ Lexer::parse_non_decimal_int_literal (location_t loc, IsDigitFunc is_digit_func,

current_column += length;

if (!has_valid_digit)
{
rust_error_at (loc, ErrorCode::E0768, "no valid digits found for number");
}

loc += length - 1;

return Token::make_int (loc, std::move (raw_str), suffix_start, base,
Expand Down
10 changes: 10 additions & 0 deletions gcc/testsuite/rust/compile/empty-non-decimal.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
#![feature(no_core)]
#![no_core]

fn main() {
let _a = 0x; // { dg-error "no valid digits found for number" }
let _b = 0b; // { dg-error "no valid digits found for number" }
let _c = 0o; // { dg-error "no valid digits found for number" }
let _d = 0x_; // { dg-error "no valid digits found for number" }
let _e = 0x_u32; // { dg-error "no valid digits found for number" }
}
Loading