compiler: Give error for byte-order-mark in middle of file.
authorIan Lance Taylor <ian@gcc.gnu.org>
Thu, 20 Sep 2012 00:54:30 +0000 (00:54 +0000)
committerIan Lance Taylor <ian@gcc.gnu.org>
Thu, 20 Sep 2012 00:54:30 +0000 (00:54 +0000)
From-SVN: r191507

gcc/go/gofrontend/lex.cc

index fa9db1f29aca1924f4e3b16aac2ebac0414d8c5c..25aaeb794a55ce2975a22e3e70a01f5a1e07d66e 100644 (file)
@@ -726,7 +726,7 @@ Lex::next_token()
                                                                &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 @@ Lex::advance_one_utf8_char(const char* p, unsigned int* value,
       *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;
 }