r224419 - clang-format: Fix incorrect calculation of token lenghts.

Daniel Jasper djasper at google.com
Wed Dec 17 01:11:08 PST 2014


Author: djasper
Date: Wed Dec 17 03:11:08 2014
New Revision: 224419

URL: http://llvm.org/viewvc/llvm-project?rev=224419&view=rev
Log:
clang-format: Fix incorrect calculation of token lenghts.

This led, e.g. to break JavaScript regex literals too early.

Modified:
    cfe/trunk/lib/Format/Format.cpp
    cfe/trunk/unittests/Format/FormatTestJS.cpp

Modified: cfe/trunk/lib/Format/Format.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/lib/Format/Format.cpp?rev=224419&r1=224418&r2=224419&view=diff
==============================================================================
--- cfe/trunk/lib/Format/Format.cpp (original)
+++ cfe/trunk/lib/Format/Format.cpp Wed Dec 17 03:11:08 2014
@@ -889,7 +889,6 @@ private:
           Column += Style.TabWidth - Column % Style.TabWidth;
           break;
         case '\\':
-          ++Column;
           if (i + 1 == e || (FormatTok->TokenText[i + 1] != '\r' &&
                              FormatTok->TokenText[i + 1] != '\n'))
             FormatTok->Type = TT_ImplicitStringLiteral;

Modified: cfe/trunk/unittests/Format/FormatTestJS.cpp
URL: http://llvm.org/viewvc/llvm-project/cfe/trunk/unittests/Format/FormatTestJS.cpp?rev=224419&r1=224418&r2=224419&view=diff
==============================================================================
--- cfe/trunk/unittests/Format/FormatTestJS.cpp (original)
+++ cfe/trunk/unittests/Format/FormatTestJS.cpp Wed Dec 17 03:11:08 2014
@@ -482,6 +482,8 @@ TEST_F(FormatTestJS, RegexLiteralLength)
   verifyFormat("var regex =\n"
                "    /aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;",
                getGoogleJSStyleWithColumns(60));
+  verifyFormat("var regex = /\\xaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa/;",
+               getGoogleJSStyleWithColumns(50));
 }
 
 TEST_F(FormatTestJS, RegexLiteralExamples) {





More information about the cfe-commits mailing list