Skip to content

clang-format always aligns stream operator << with spaces #59797

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

Open
knarfS opened this issue Jan 3, 2023 · 2 comments
Open

clang-format always aligns stream operator << with spaces #59797

knarfS opened this issue Jan 3, 2023 · 2 comments

Comments

@knarfS
Copy link

knarfS commented Jan 3, 2023

Description

The UseTab option is set to Always, but clang-format is using spaces to align the << operator in continued lines. This behavior occurs even when all the Align* options are set to false. Also BreakBeforeBinaryOperators has no influence on the alignment (or even breaking before/after) of the stream operator <<.

The unwanted leading spaces then trigger other format checkers like EditorConfig (which is set to indent_style·=·tab)

Steps to reproduce

  1. Create a minimal .clang-format file with the following configuration:
---
AlignAfterOpenBracket: DontAlign
AlignConsecutiveMacros: false
AlignConsecutiveAssignments: false
AlignConsecutiveDeclarations: false
AlignEscapedNewlines: Left
AlignOperands: DontAlign
AlignTrailingComments: false
BreakBeforeBinaryOperators: NonAssignment
ColumnLimit: 80
ContinuationIndentWidth: 4
IndentWidth: 4
TabWidth: 4
UseTab: Always
...
  1. Use clang-format to format the following code:
void someFunction() {
	std::cout << someVariable << "Some random string for std::cout " << someOtherVariable << ", "
		<< andAnotherOne << andOneMore << ", some final text.";
}

Expected behavior

The << operators in the continued lines should not be aligned and only be indented with tab characters, not with spaces:

void someFunction() {
	std::cout << someVariable << "Some random string for std::cout "
		<< someOtherVariable << ", " << andAnotherOne << andOneMore
		<< ", some final text.";
}

Actual behavior

The << operators in the continued lines are indented with three tabs and with two additional spaces for alignment:

void someFunction() {
	std::cout << someVariable << "Some random string for std::cout "
			  << someOtherVariable << ", " << andAnotherOne << andOneMore
			  << ", some final text.";
}

Environment

  • clang-format version: Debian clang-format version 14.0.6
  • Operating system: Debian Testing x86_64
@knarfS
Copy link
Author

knarfS commented Jan 3, 2023

The issue #44363 is somewhat related to this issue. It describes a not configurable and in some cases unwanted behavior when it comes to stream operators and breaking lines.

@llvmbot
Copy link
Member

llvmbot commented Jan 3, 2023

@llvm/issue-subscribers-clang-format

s1Sharp pushed a commit to s1Sharp/llvm-project that referenced this issue Oct 23, 2023
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 llvm#59797
Fixes llvm#44363
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants