Skip to content

[clang-format] Add space after a word token #92741

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
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion clang/lib/Format/TokenAnnotator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5280,7 +5280,8 @@ bool TokenAnnotator::spaceRequiredBefore(const AnnotatedLine &Line,
// handled.
if (Left.is(tok::amp) && Right.is(tok::r_square))
return Style.SpacesInSquareBrackets;
return Style.SpaceAfterLogicalNot && Left.is(tok::exclaim);
return (Style.SpaceAfterLogicalNot && Left.is(tok::exclaim)) ||
Right.is(TT_BinaryOperator);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This line was deleted in #90161. Adding it back will hide the uncovered bug and only fix #92688 superficially IMO. For example, SpaceBeforeAssignmentOperators will have no effect.

}

// If the next token is a binary operator or a selector name, we have
Expand Down
7 changes: 7 additions & 0 deletions clang/unittests/Format/FormatTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -24545,6 +24545,13 @@ TEST_F(FormatTest, STLWhileNotDefineChed) {
"#endif // while");
}

TEST_F(FormatTest, BinaryOperatorAfterUnaryOperator) {
verifyFormat("void test(void) {\n"
" static void (*xor)(uint8_t *, size_t, uint8_t);\n"
" xor = resolve_xor_x86();\n"
"}");
}

TEST_F(FormatTest, OperatorSpacing) {
FormatStyle Style = getLLVMStyle();
Style.PointerAlignment = FormatStyle::PAS_Right;
Expand Down
Loading