This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

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


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

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]