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

login
register
mail settings
Submitter Ian Taylor
Date Sept. 20, 2012, 12:54 a.m.
Message ID <mcr392dqzsg.fsf@google.com>
Download mbox | patch
Permalink /patch/185274/
State New
Headers show

Comments

Ian Taylor - Sept. 20, 2012, 12:54 a.m.
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

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;
 }