diff mbox

Go patch committed: Error for byte-order-mark in middle of file

Message ID mcr392dqzsg.fsf@google.com
State New
Headers show

Commit Message

Ian Lance Taylor Sept. 20, 2012, 12:54 a.m. UTC
I should have looked at some more of the testsuite before my last
patch.  This patch to the Go frontend issues an error for a Unicode
byte-order-mark in the middle of a Go file, while continuing to ignore
it at the beginning of the file.  Bootstrapped and ran Go testsuite on
x86_64-unknown-linxu-gnu.  Committed to mainline.  Will commit to 4.7
branch when it reopens.

Ian
diff mbox

Patch

diff -r 917ece6aa599 go/lex.cc
--- a/go/lex.cc	Wed Sep 19 08:50:19 2012 -0700
+++ b/go/lex.cc	Wed Sep 19 17:47:42 2012 -0700
@@ -726,7 +726,7 @@ 
 								&issued_error);
 
 		// Ignore byte order mark at start of file.
-		if (ci == 0xfeff && this->lineno_ == 1 && this->lineoff_ == 0)
+		if (ci == 0xfeff)
 		  {
 		    p = pnext;
 		    break;
@@ -840,6 +840,14 @@ 
       *issued_error = true;
       return p + 1;
     }
+
+  // Warn about byte order mark, except at start of file.
+  if (*value == 0xfeff && (this->lineno_ != 1 || this->lineoff_ != 0))
+    {
+      error_at(this->location(), "Unicode (UTF-8) BOM in middle of file");
+      *issued_error = true;
+    }
+
   return p + adv;
 }