-
Notifications
You must be signed in to change notification settings - Fork 15.3k
[clang-format] Keep the space between not and a unary operator
#135035
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
Merged
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Based on the documentation, it can be argued that SpaceAfterLogicalNot doesn't cover the alternative operator `not`. Closes llvm#125465
Member
|
@llvm/pr-subscribers-clang-format Author: Owen Pan (owenca) ChangesBased on the documentation, it can be argued that SpaceAfterLogicalNot doesn't cover the alternative operator Closes #125465 Full diff: https://github.com/llvm/llvm-project/pull/135035.diff 2 Files Affected:
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index bd54470dcba37..31f8a71256fe8 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -5472,7 +5472,12 @@ 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);
+ if (Left.isNot(tok::exclaim))
+ return false;
+ if (Left.TokenText == "!")
+ return Style.SpaceAfterLogicalNot;
+ assert(Left.TokenText == "not");
+ return Right.isOneOf(tok::coloncolon, TT_UnaryOperator);
}
// If the next token is a binary operator or a selector name, we have
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index 69c9ee1d1dcb2..f0e67c604cc4b 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -25393,8 +25393,10 @@ TEST_F(FormatTest, AlternativeOperators) {
verifyFormat("%:define ABC abc"); // #define ABC abc
verifyFormat("%:%:"); // ##
+ verifyFormat("return not ::f();");
+ verifyFormat("return not *foo;");
+
verifyFormat("a = v(not;);\n"
- "b = v(not+);\n"
"c = v(not x);\n"
"d = v(not 1);\n"
"e = v(not 123.f);");
@@ -25402,7 +25404,6 @@ TEST_F(FormatTest, AlternativeOperators) {
verifyNoChange("#define ASSEMBLER_INSTRUCTION_LIST(V) \\\n"
" V(and) \\\n"
" V(not) \\\n"
- " V(not!) \\\n"
" V(other)",
getLLVMStyleWithColumns(40));
}
|
HazardyKnusperkeks
approved these changes
Apr 9, 2025
mydeveloperday
approved these changes
Apr 9, 2025
Contributor
Author
|
/cherry-pick f344838 |
Member
Error: Command failed due to missing milestone. |
Contributor
Author
|
/cherry-pick f344838 |
Member
|
/pull-request #135118 |
AllinLeeYL
pushed a commit
to AllinLeeYL/llvm-project
that referenced
this pull request
Apr 10, 2025
…m#135035) Also keep the space between `not` and `::`. Based on the [documentation](https://releases.llvm.org/20.1.0/tools/clang/docs/ClangFormatStyleOptions.html#spaceafterlogicalnot), it can be argued that SpaceAfterLogicalNot doesn't cover the alternative operator `not`. Closes llvm#125465
swift-ci
pushed a commit
to swiftlang/llvm-project
that referenced
this pull request
Apr 11, 2025
…m#135035) Also keep the space between `not` and `::`. Based on the [documentation](https://releases.llvm.org/20.1.0/tools/clang/docs/ClangFormatStyleOptions.html#spaceafterlogicalnot), it can be argued that SpaceAfterLogicalNot doesn't cover the alternative operator `not`. Closes llvm#125465 (cherry picked from commit f344838)
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Also keep the space between
notand::.Based on the documentation, it can be argued that SpaceAfterLogicalNot doesn't cover the alternative operator
not.Closes #125465