aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2015-08-25 21:17:47 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2015-08-25 21:17:47 +0000
commit387b37c1acab0791f19cfced1e345543855d764e (patch)
tree51e3958a1fe1dce71f49ef708a9b04152b34b6c8 /gcc/go
parent60c47c007366840f15fe17913d0592c2819b7c99 (diff)
downloadgcc-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')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/lex.cc10
2 files changed, 9 insertions, 3 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 86d163b..c30efd9 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-14ca4b6130b9a7132d132f418e9ea283b3a52c08
+f97d579fa8431af5cfde9b0a48604caabfd09377
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
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);