[PATCH] D80950: [clang-format] [PR44542,38872] String << String always get a forced newline.

MyDeveloperDay via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 4 02:07:56 PDT 2020


MyDeveloperDay added a comment.

Just to add, I also think although because there are no tests to enforce it the primary reason is for when we see '\n', breaking the stream on endl but this is actually covered by another rule this also in mustBreak()

  if (Current.is(tok::lessless) &&
      ((Previous.is(tok::identifier) && Previous.TokenText == "endl") ||
       (Previous.Tok.isLiteral() && (Previous.TokenText.endswith("\\n\"") ||
                                     Previous.TokenText == "\'\\n\'"))))
    return true;

Is going to break on what is most likely a natural heuristics where `\n` separates different lines

  LOG_IF(DFATAL, a < b) << "Equality condition can never be satisfied:"
                        << " foo=" << a << endl
                        << " is less than "
                        << " bar=" << b;
  
  LOG_IF(DFATAL, a < b) << "Equality condition can never be satisfied:"
                        << " foo=" << a << "\n"
                        << " is less than "
                        << " bar=" << b;

but this is also flawed depending on what precedes the newline

  LOG_IF(DFATAL, a < b) << "Equality condition can never be satisfied:"
                        << " foo=" << a << " and " << endl
                        << " is less than "
                        << " bar=" << b;
  
  LOG_IF(DFATAL, a < b) << "Equality condition can never be satisfied:"
                        << " foo=" << a << " and "
                        << "\n"
                        << " is less than "
                        << " bar=" << b;

I guess these rules were a good first compromise.. and more likely you'd want different rules depending on how large the streaming operations.


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D80950/new/

https://reviews.llvm.org/D80950





More information about the cfe-commits mailing list