[PATCH] Don't break string literals inside preprocessor directives.

Alexander Kornienko alexfh at google.com
Fri Oct 11 14:46:53 PDT 2013


  Fixed and committed as r192507.


================
Comment at: lib/Format/ContinuationIndenter.cpp:697
@@ -692,1 +696,3 @@
+    // preprocessor directives that contain long string literals.
+    if (State.Line->Type == LT_PreprocessorDirective) return 0;
     // Exempts unterminated string literals from line breaking. The user will
----------------
Daniel Jasper wrote:
> We don't do one-line ifs in LLVM style.
It was the result of testing clang-format-diff.py with a wrong style. I've fixed this locally already.

================
Comment at: lib/Format/ContinuationIndenter.cpp:700
@@ -693,4 +699,3 @@
     // likely want to terminate the string before any line breaking is done.
-    if (Current.IsUnterminatedLiteral)
-      return 0;
+    if (Current.IsUnterminatedLiteral) return 0;
 
----------------
Daniel Jasper wrote:
> same as above
ditto

================
Comment at: lib/Format/TokenAnnotator.cpp:1049-1052
@@ -1044,5 +1048,6 @@
       Current->SpacesRequiredBefore = Style.SpacesBeforeTrailingComments;
     else
       Current->SpacesRequiredBefore =
-          spaceRequiredBefore(Line, *Current) ? 1 : 0;
+          std::max(Current->SpacesRequiredBefore,
+                   spaceRequiredBefore(Line, *Current) ? 1U : 0);
 
----------------
Daniel Jasper wrote:
> How about instead:
> 
>   else if (Current->SpacesRequiredBefore == 0 && spaceRequiredBefore(Line, *Current))
>     Current->SpacesRequiredBefore = 1;
Yep, this is less hairy. Changed.


http://llvm-reviews.chandlerc.com/D1813

COMMIT
  http://llvm-reviews.chandlerc.com/rL192507



More information about the cfe-commits mailing list