For convenience with some Windows editors, the other Go compiler was
modified to permit a byte-order-mark (0xfeff) at the start of a .go
file.  This byte-order-mark is meaningless when using UTF-8, but
apparently some editors introduce it anyhow.  This patch changes the
gccgo frontend to also ignore the mark at the start of a file.
Bootstrapped and ran Go testsuite on x86_64-unknown-linux-gnu.
Committed to mainline.  Will commit to 4.7 branch when it is open for
commits.

Ian

diff -r 858f39eca5c5 go/lex.cc
--- a/go/lex.cc	Tue Sep 18 22:24:35 2012 -0700
+++ b/go/lex.cc	Wed Sep 19 08:45:16 2012 -0700
@@ -722,7 +722,16 @@
 		unsigned int ci;
 		bool issued_error;
 		this->lineoff_ = p - this->linebuf_;
-		this->advance_one_utf8_char(p, &ci, &issued_error);
+		const char *pnext = this->advance_one_utf8_char(p, &ci,
+								&issued_error);
+
+		// Ignore byte order mark at start of file.
+		if (ci == 0xfeff && this->lineno_ == 1 && this->lineoff_ == 0)
+		  {
+		    p = pnext;
+		    break;
+		  }
+
 		if (Lex::is_unicode_letter(ci))
 		  return this->gather_identifier();
 

Reply via email to