[PATCH] [WIP] clang-format: Enforce EOL at EOF as required by C standard

Alp Toker alp at nuanti.com
Sun Oct 6 13:50:53 PDT 2013

On 06/10/2013 21:10, Alp Toker wrote:
>> I am sorry that you regard the response as negative.. I probably just
>> don't understand some of your reasoning and am thus leaning towards
>> solving this in a slightly different fashion.
> I see where you're coming from but it doesn't quite work for solving the
> tooling problems AFAICT.
> So, I think this topic is worth re-visiting some weeks down the line
> once we've had a chance to digest the matter.
In the meantime, here's a standalone fix for the exit code mentioned in
the original patch.

I'm not sure how to write a portable test for this, any idea where to look?

the browser experts

-------------- next part --------------
commit 3db8eecd5ffb2940032fad386126bfbf0e84c5b9
Author: Alp Toker <alp at nuanti.com>
Date:   Sun Oct 6 21:27:21 2013 +0100

    clang-format: Don't exit with failure on empty files

diff --git a/tools/clang-format/ClangFormat.cpp b/tools/clang-format/ClangFormat.cpp
index e08aa2d..2ca2bed 100644
--- a/tools/clang-format/ClangFormat.cpp
+++ b/tools/clang-format/ClangFormat.cpp
@@ -186,7 +186,7 @@ static bool format(std::string FileName) {
     return true;
   if (Code->getBufferSize() == 0)
-    return true; // Empty files are formatted correctly.
+    return false; // Empty files are formatted correctly.
   FileID ID = createInMemoryFile(FileName, Code.get(), Sources, Files);
   std::vector<CharSourceRange> Ranges;
   if (fillRanges(Sources, ID, Code.get(), Ranges))
diff --git a/tools/clang-format/clang-format-diff.py b/tools/clang-format/clang-format-diff.py
index 90723d2..abd1c7e 100755
--- a/tools/clang-format/clang-format-diff.py
+++ b/tools/clang-format/clang-format-diff.py
@@ -81,7 +81,8 @@ def main():
     stdout, stderr = p.communicate()
     if stderr:
       print stderr
-      return
+    if p.returncode != 0:
+      sys.exit(p.returncode)
 if __name__ == '__main__':

More information about the cfe-commits mailing list