[PATCH] D36019: [clang-format] Fix bug with ENAS_DontAlign and empty lines

Daniel Jasper via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 4 01:20:00 PDT 2017


djasper added inline comments.


================
Comment at: lib/Format/WhitespaceManager.cpp:650
+    for (unsigned i = 0; i < Newlines; ++i)
+      Text.append(UseCRLF ? " \\\r\n" : " \\\n");
+    return;
----------------
Note that when you have an empty line, this would turn into:

  #define A \
    int i; \
   \                <-- Note the 1-space indent here.
    int j; \
    int k;

With my alternative below, that "\" will just be put at column 0, which probably isn't better or worse.


================
Comment at: lib/Format/WhitespaceManager.cpp:656
+    assert(EscapedNewlineColumn >= 1);
     unsigned Offset =
+        std::min<int>(EscapedNewlineColumn - 1, PreviousEndOfTokenColumn);
----------------
You could change this to:

  unsigned Spaces =
      std::max<int>(1, EscapedNewlineColumn - PreviousEndOfTokenColumn - 1);
  for (unsigned i = 0; i < Newlines; ++i) {
    Text.append(Spaces, ' ');
    Text.append(UseCRLF ? "\\\r\n" : "\\\n");
    Spaces = std::max<int>(0, EscapedNewlineColumn - 1);
  }

And it should work without problems and without special code path.


https://reviews.llvm.org/D36019





More information about the cfe-commits mailing list