[clang] [clang-format] Break after string literals with trailing line breaks (PR #76795)

kadir çetinkaya via cfe-commits cfe-commits at lists.llvm.org
Mon Jan 8 01:20:13 PST 2024


================
@@ -5151,6 +5151,14 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
     return true;
   if (Left.IsUnterminatedLiteral)
     return true;
+  // FIXME: Breaking after newlines seems useful in general. Turn this into an
+  // option and recognize more cases like endl etc, and break independent of
+  // what comes after operator lessless.
+  if (Right.is(tok::lessless) && Right.Next &&
+      Right.Next->is(tok::string_literal) && Left.is(tok::string_literal) &&
+      Left.TokenText.ends_with("\\n\"")) {
----------------
kadircet wrote:

> We can also handle \n and endl now. For example:

yes, but that'll be "new" behavior, and even if we do that, i'd rather do that in a separate patch that can be reviewed/reverted on it's own.

as mentioned, this is mostly to restore some of the "incidental" behavior that was relied on by codebases in the wild. so that changes in the new clang-format release will be minimal.

https://github.com/llvm/llvm-project/pull/76795


More information about the cfe-commits mailing list