Skip to content

[clang-format] Formatting chained stream output (bitwise left shift) operators << #93034

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Alexolut opened this issue May 22, 2024 · 5 comments
Labels
clang-format duplicate Resolved as duplicate

Comments

@Alexolut
Copy link

In clang-format 18.1.0-18.1.4 the following code doesn't changed after formatting based on Google-style:

stream << "A" << "B" << "C" << "D";

In other words as long as we fit in line length, all is places in one line.

But in 18.1.5 and 18.1.6 every operand is placed on the different line despite the allowed length of line like this:

stream << "A"
       << "B"
       << "C"
       << "D";

Which behavior is considered correct? Is there a way to configure this behavior by some format option?

@Alexolut Alexolut changed the title Formatting chained stream output (bitwise left shift) operators << [clang-format] Formatting chained stream output (bitwise left shift) operators << May 22, 2024
@llvmbot
Copy link
Member

llvmbot commented May 22, 2024

@llvm/issue-subscribers-clang-format

Author: None (Alexolut)

In clang-format 18.1.0-18.1.4 the following code doesn't changed after formatting based on Google-style:
stream &lt;&lt; "A" &lt;&lt; "B" &lt;&lt; "C" &lt;&lt; "D";

In other words as long as we fit in line length, all is places in one line.

But in 18.1.5 and 18.1.6 every operand is placed on the different line despite the allowed length of line like this:

stream &lt;&lt; "A"
       &lt;&lt; "B"
       &lt;&lt; "C"
       &lt;&lt; "D";

Which behavior is considered correct? Is there a way to configure this behavior by some format option?

@owenca
Copy link
Contributor

owenca commented May 24, 2024

In clang-format 18.1.0-18.1.4 the following code doesn't changed after formatting based on Google-style:

stream << "A" << "B" << "C" << "D";

In other words as long as we fit in line length, all is places in one line.

But in 18.1.5 and 18.1.6 every operand is placed on the different line despite the allowed length of line like this:

stream << "A"
       << "B"
       << "C"
       << "D";

Please see the release notes of 18.1.5.

Which behavior is considered correct? Is there a way to configure this behavior by some format option?

See #92214, which addresses the issues post 18.1.6.

@Alexolut
Copy link
Author

See #92214, which addresses the issues post 18.1.6.

Am I understand you correctly, that for versions newer than 18.1.6 expected behavior will be "Leave as is" for both code excerpts that I mentioned at the top of the thread?

stream << "A"
       << "B"
       << "C"
       << "D";
stream << "A" << "B" << "C" << "D";

Will something like this:

stream              << "A" <<            "B"
  << "C"
                      << "D";

be formatted in this way?

stream << "A" << "B"
       << "C"
       << "D";

@owenca
Copy link
Contributor

owenca commented May 25, 2024

@Alexolut exactly!

@owenca owenca added the duplicate Resolved as duplicate label May 27, 2024
@owenca
Copy link
Contributor

owenca commented May 27, 2024

Duplicate of #44363.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
clang-format duplicate Resolved as duplicate
Projects
None yet
Development

No branches or pull requests

4 participants