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

2024-01-03 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

> @s1Sharp are there any conclusions here? our code also incidentally relied on 
> having new lines between string literals, mostly for the sake of having a 
> line break after string literals that end with `\n`.
> 
> what do people think about restoring the functionality to break after string 
> literals that end with `\n`? 
> https://github.com/search?q=%2F%5C%5Cn%5C%22%5Cn%5Cs*%3C%3C%5C+%5C%22%2F+language%3AC%2B%2B+&type=code&ref=advsearch
>  shows a lot of examples of such pattern, so i feel like having that without 
> an option initially easy relatively easy and likely to preserve 
> clang-format's behavior for a lot of existing code for the next release. 
> afterwards we can discuss introducing more options again.

First, I want to show how this works with the current code.
As an example, here are a couple of output statements.

.clang-format:
```
Language: Cpp
BasedOnStyle: Google

IndentWidth: 4

ColumnLimit: 70
```

before clang-format:
```C++
  cout << "hello\n" << "World\n" << "HELLO" << "world" << "hello" << "World" << 
"HELLO" << "world" << "hello" << "World" << "HELLO" << "world";

  cout << "hello" << std::endl << "World" << "hello" << '\n' << "another hello" 
<< "world";

  cout << "hello\n"
   << "World" << std::endl
   << "HELLO" << "world";
```

after clang-format:
```C++
cout << "hello\n"
 << "World\n"
 << "HELLO" << "world" << "hello" << "World" << "HELLO"
 << "world" << "hello" << "World" << "HELLO" << "world";

cout << "hello" << std::endl
 << "World" << "hello" << '\n'
 << "another hello" << "world";

cout << "hello\n" << "World" << std::endl << "HELLO" << "world";

```

A bit unexpected results, right? Formatting applies to single-line expressions 
and breaks to another line after the \n and std::endl characters. And if the 
code has already been manually formatted (as in 3rd cout), then clang-format 
groups this code into a single-line expression.

I agree with your suggestion that to maintain compatibility with the old 
behavior of clang-format.


https://github.com/llvm/llvm-project/pull/69859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2024-01-03 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

It seems your changes remain compatible with the old clang-format behavior.
Сode looks quite correct

https://github.com/llvm/llvm-project/pull/76795
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-21 Thread Tsarkov Maksim via cfe-commits

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

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

>From 383d1acd4a5726296b09681103874f071529dacc Mon Sep 17 00:00:00 2001
From: Tsarkov Maksim 
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
---
 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)) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-21 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

I have no way to link the issues related to the PR issue. I don't know why, but 
add a link to issue to this comment 
https://github.com/llvm/llvm-project/issues/44363 .
So, I want to start a little discussion about the solution.

I'll start with the problem - when using the BreakBeforeBinaryOperators: None 
option, I expect that the code
```C++
std::cout << "hello " << "world!";
```
with binary output operation to stream via token "<<" (tok::lessless)
clang-format output is:
```C++
std::cout << "hello "
 << "world!";
```
This was unexpected for me and unnecessary, as well as for other users who have 
already created issues.
The token '<<' is a binary operator that have link to the 
"BreakBeforeBinaryOperators" option.

1th solution is: Apply the break of the binary operator '<<' only if 
BreakBeforeBinaryOperators is [All | NonAssignment].And npt break if 
BreakBeforeBinaryOperators is None. This solution is very simple, but, in my 
opinion, violates the user api and the user's expectations of the clang-format 
program.

2th solution is: Add new option that allowing specific behaviour, such as 
"BreakAfterStreamOperator" or "BreakAfterLessLessOperator" with options [ Leave 
| NoFitLine | All ].


I am open to discussions


https://github.com/llvm/llvm-project/pull/69859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-23 Thread Tsarkov Maksim via cfe-commits

https://github.com/s1Sharp reopened 
https://github.com/llvm/llvm-project/pull/69859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-23 Thread Tsarkov Maksim via cfe-commits

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

>From a5c62614113b4c42e9051905bb6165331192ded0 Mon Sep 17 00:00:00 2001
From: Tsarkov Maksim 
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 a457ced9f886846..fea5b809824d3e3 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5118,7 +5118,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)) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Don't break between string literal operands of << (PR #69871)

2023-10-23 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

this is good to be respectful. Please, lets check my mr 
https://github.com/llvm/llvm-project/pull/69859 also

https://github.com/llvm/llvm-project/pull/69871
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-23 Thread Tsarkov Maksim via cfe-commits

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 
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)) {

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


[clang] [clang-format] Don't break between string literal operands of << (PR #69871)

2023-10-23 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

I think adding the possibility of breaking '<<' is a good idea if it's 
optional, what do u think?

https://github.com/llvm/llvm-project/pull/69871
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-23 Thread Tsarkov Maksim via cfe-commits

https://github.com/s1Sharp edited 
https://github.com/llvm/llvm-project/pull/69859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-10-24 Thread Tsarkov Maksim via cfe-commits

s1Sharp wrote:

yes, issue with breaking after << is gone. I want to get your point about 
functionality clang-format and implementing new option such as 
"BreakAfterStreamOperator". As i can see, @HazardyKnusperkeks you agree with 
"owenca" point?

May be i can do something with this feature

https://github.com/llvm/llvm-project/pull/69859
___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits