diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-08-25 21:17:47 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2015-08-25 21:17:47 +0000 |
commit | 387b37c1acab0791f19cfced1e345543855d764e (patch) | |
tree | 51e3958a1fe1dce71f49ef708a9b04152b34b6c8 /gcc/go/gofrontend/lex.cc | |
parent | 60c47c007366840f15fe17913d0592c2819b7c99 (diff) | |
download | gcc-387b37c1acab0791f19cfced1e345543855d764e.zip gcc-387b37c1acab0791f19cfced1e345543855d764e.tar.gz gcc-387b37c1acab0791f19cfced1e345543855d764e.tar.bz2 |
compiler: Accept numeric literals with leading zeroes.
When a numeric literal with leading zeroes was seen in the parser, it
would only be accepted if it were a valid hex or octal literal. Any
invalid numeric literal would be split up into multiple tokens: the
valid hex/octal literal followed by the rest of the characters.
Instead, when scanning a numeric literal with leading zeroes, always
accept the number and give an appropriate error if the accepted number
does not fit in the expected base.
Fixes golang/go#11532, golang/go#11533.
Reviewed-on: https://go-review.googlesource.com/13791
From-SVN: r227193
Diffstat (limited to 'gcc/go/gofrontend/lex.cc')
-rw-r--r-- | gcc/go/gofrontend/lex.cc | 10 |
1 files changed, 8 insertions, 2 deletions
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc index 8de94c5..632a1c9 100644 --- a/gcc/go/gofrontend/lex.cc +++ b/gcc/go/gofrontend/lex.cc @@ -1047,7 +1047,7 @@ Lex::gather_number() pnum = p; while (p < pend) { - if (*p < '0' || *p > '7') + if (*p < '0' || *p > '9') break; ++p; } @@ -1060,7 +1060,13 @@ Lex::gather_number() std::string s(pnum, p - pnum); mpz_t val; int r = mpz_init_set_str(val, s.c_str(), base); - go_assert(r == 0); + if (r != 0) + { + if (base == 8) + error_at(this->location(), "invalid octal literal"); + else + error_at(this->location(), "invalid hex literal"); + } if (neg) mpz_neg(val, val); |