[clang] [clang-format] unexpected break after binOp '<<' (PR #69859)

Tsarkov Maksim via cfe-commits cfe-commits at lists.llvm.org
Mon Oct 23 06:17:16 PDT 2023


https://github.com/s1Sharp updated https://github.com/llvm/llvm-project/pull/69859

>From 5bbff07c636c2fc8b0432e5ca615d4cd7fd0c2b1 Mon Sep 17 00:00:00 2001
From: Tsarkov Maksim <mtsarkov at naumen.ru>
Date: Sun, 22 Oct 2023 02:09:21 +0300
Subject: [PATCH] [clang-format] unexpected break after binOp '<<'

the problem occurred while checking for the correctness of the break after binary operators.
The output statement 'tok::lessless' is then break line every possible time,
which is not expected with the BreakBeforeBinaryOperators: None

Fixes https://github.com/llvm/llvm-project/issues/59797
Fixes https://github.com/llvm/llvm-project/issues/44363
---
 clang/lib/Format/TokenAnnotator.cpp | 4 +++-
 1 file changed, 3 insertions(+), 1 deletion(-)

diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index 7f85f48de2ed2ed..6db1e826e11d234 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5119,7 +5119,9 @@ bool TokenAnnotator::mustBreakBefore(const AnnotatedLine &Line,
   if (Left.IsUnterminatedLiteral)
     return true;
   if (Right.is(tok::lessless) && Right.Next && Left.is(tok::string_literal) &&
-      Right.Next->is(tok::string_literal)) {
+      Right.Next->is(tok::string_literal) &&
+      (Style.BreakBeforeBinaryOperators == FormatStyle::BOS_All ||
+       Style.BreakBeforeBinaryOperators == FormatStyle::BOS_NonAssignment)) {
     return true;
   }
   if (Right.is(TT_RequiresClause)) {



More information about the cfe-commits mailing list