diff options
author | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-10-11 17:04:42 +0000 |
---|---|---|
committer | ian <ian@138bc75d-0d04-0410-961f-82ee72b054a4> | 2013-10-11 17:04:42 +0000 |
commit | d9771d73ec1a3bf42251870b496baafc20a439ad (patch) | |
tree | faca9fbb9a77f74bdf00ff5c082b3032b8c2397e /gcc/go | |
parent | cc6b4e73ea412e972453c37b38ecf1ae636ce0ed (diff) | |
download | gcc-d9771d73ec1a3bf42251870b496baafc20a439ad.tar.gz |
compiler: Improve handling of invalid ASCII characters in identifiers.
git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@203450 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/lex.cc | 23 |
1 files changed, 22 insertions, 1 deletions
diff --git a/gcc/go/gofrontend/lex.cc b/gcc/go/gofrontend/lex.cc index 22a1f6e2a0c..16169634733 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) { |