Hello,

 could somebody please review the attached simple patch for PR15664?

 The patch intentionally doesn't do anything fancy except simply removing the 
BOM (which should be unnecessary for UTF-8 anyway). I'm not sure what 
handling other UTF encodings would exactly require, and it's surely better to 
keep the compilation obviously fail for whoever will possibly run into that 
one day and provide a testcase.

-- 
 Lubos Lunak
From 4491c3213d818db8feee5d056bf9ffe87c5692f5 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?Lubo=C5=A1=20Lu=C5=88=C3=A1k?= <[email protected]>
Date: Wed, 27 Nov 2013 12:43:30 +0100
Subject: [PATCH] strip UTF-8 BOM in -frewrite-includes (PR#15664)

---
 lib/Rewrite/Frontend/InclusionRewriter.cpp | 5 +++++
 1 file changed, 5 insertions(+)

diff --git a/lib/Rewrite/Frontend/InclusionRewriter.cpp b/lib/Rewrite/Frontend/InclusionRewriter.cpp
index bd4250a..71ceb5f 100644
--- a/lib/Rewrite/Frontend/InclusionRewriter.cpp
+++ b/lib/Rewrite/Frontend/InclusionRewriter.cpp
@@ -367,6 +367,11 @@ bool InclusionRewriter::Process(FileID FileId,
   unsigned NextToWrite = 0;
   int Line = 1; // The current input file line number.
 
+  // Ignore UTF-8 BOM, otherwise it'd end up somewhere else than the start
+  // of the resulting file.
+  if (FromFile.getBuffer().startswith("\xEF\xBB\xBF"))
+    NextToWrite = 3;
+
   Token RawToken;
   RawLex.LexFromRawLexer(RawToken);
 
-- 
1.8.1.4

_______________________________________________
cfe-commits mailing list
[email protected]
http://lists.cs.uiuc.edu/mailman/listinfo/cfe-commits

Reply via email to