aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2013-10-11 17:04:42 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2013-10-11 17:04:42 +0000
commite169e8b0ca1540ca16140b7576ca6324a566228f (patch)
treefaca9fbb9a77f74bdf00ff5c082b3032b8c2397e
parent20e8fa532721590da0c89a8f442a9d1197eb2083 (diff)
downloadgcc-e169e8b0ca1540ca16140b7576ca6324a566228f.zip
gcc-e169e8b0ca1540ca16140b7576ca6324a566228f.tar.gz
gcc-e169e8b0ca1540ca16140b7576ca6324a566228f.tar.bz2
compiler: Improve handling of invalid ASCII characters in identifiers.
From-SVN: r203450
-rw-r--r--gcc/go/gofrontend/lex.cc23
1 files changed, 22 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc
index 22a1f6e2..1616963 100644
--- a/gcc/go/gofrontend/lex.cc
+++ b/gcc/go/gofrontend/lex.cc
@@ -873,7 +873,28 @@ Lex::gather_identifier()
&& (cc < 'a' || cc > 'z')
&& cc != '_'
&& (cc < '0' || cc > '9'))
- break;
+ {
+ // Check for an invalid character here, as we get better
+ // error behaviour if we swallow them as part of the
+ // identifier we are building.
+ if ((cc >= ' ' && cc < 0x7f)
+ || cc == '\t'
+ || cc == '\r'
+ || cc == '\n')
+ break;
+
+ this->lineoff_ = p - this->linebuf_;
+ error_at(this->location(),
+ "invalid character 0x%x in identifier",
+ cc);
+ if (!has_non_ascii_char)
+ {
+ buf.assign(pstart, p - pstart);
+ has_non_ascii_char = true;
+ }
+ if (!Lex::is_invalid_identifier(buf))
+ buf.append("$INVALID$");
+ }
++p;
if (is_first)
{