[PATCH] D152443: Add SpaceAfterOperatorKeyword & SpaceAfterOperatorKeywordInCall style options for clang-format

Alexander Hinze via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Thu Jun 8 18:09:05 PDT 2023


KitsuneAlex updated this revision to Diff 529798.
KitsuneAlex added a comment.

Some additional changes because i exceeded the maximum line width on multiple occasions.


Herald added a comment.

NOTE: Clang-Format Team Automated Review Comment

Your review contains a change to clang/include/clang/Format/Format.h but does not contain an update to ClangFormatStyleOptions.rst

ClangFormatStyleOptions.rst is generated via clang/docs/tools/dump_format_style.py,  please run this to regenerate the .rst

You can validate that the rst is valid by running.

  ./docs/tools/dump_format_style.py
  mkdir -p html
  /usr/bin/sphinx-build -n ./docs ./html


Repository:
  rG LLVM Github Monorepo

CHANGES SINCE LAST ACTION
  https://reviews.llvm.org/D152443/new/

https://reviews.llvm.org/D152443

Files:
  clang/include/clang/Format/Format.h
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/FormatTest.cpp


Index: clang/unittests/Format/FormatTest.cpp
===================================================================
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22904,7 +22904,6 @@
 TEST_F(FormatTest, SpaceAfterOperatorKeyword) {
   FormatStyle Style = getLLVMStyle();
   verifyFormat("bool operator==();", Style);
-
   Style.SpaceAfterOperatorKeyword = true;
   verifyFormat("bool operator ==();", Style);
 }
@@ -22913,7 +22912,6 @@
   FormatStyle Style = getLLVMStyle();
   verifyFormat("foo.operator==();", Style);
   verifyFormat("foo.Foo::operator==();", Style);
-  
   Style.SpaceAfterOperatorKeywordInCall = true;
   verifyFormat("foo.operator ==();", Style);
   verifyFormat("foo.Foo::operator ==();", Style);
Index: clang/lib/Format/TokenAnnotator.cpp
===================================================================
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4201,13 +4201,13 @@
     // Space in __attribute__((attr)) ::type.
     if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon))
       return true;
-
     if (Left.is(tok::kw_operator)) {
-      if (Left.Previous && Left.Previous->isOneOf(tok::coloncolon, tok::period))
-        return Style.SpaceAfterOperatorKeywordInCall || Right.is(tok::coloncolon);
+      if (Left.Previous && 
+          Left.Previous->isOneOf(tok::coloncolon, tok::period))
+        return Style.SpaceAfterOperatorKeywordInCall ||
+               Right.is(tok::coloncolon);
       return Style.SpaceAfterOperatorKeyword || Right.is(tok::coloncolon);
     }
-
     if (Right.is(tok::l_brace) && Right.is(BK_BracedInit) &&
         !Left.opensScope() && Style.SpaceBeforeCpp11BracedList) {
       return true;
Index: clang/include/clang/Format/Format.h
===================================================================
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3701,7 +3701,6 @@
   bool SpaceAfterOperatorKeyword;
 
   /// If \c true, a space will be inserted after the 'operator' keyword in a call expression.
-  /// This option defaults to SpaceAfterOperatorKeyword.
   /// \code
   ///    true:                                  false:
   ///    foo.operator ==(...);         vs.      foo.operator==(...);
@@ -4430,7 +4429,8 @@
            SpaceAfterCStyleCast == R.SpaceAfterCStyleCast &&
            SpaceAfterLogicalNot == R.SpaceAfterLogicalNot &&
            SpaceAfterOperatorKeyword == R.SpaceAfterOperatorKeyword &&
-           SpaceAfterOperatorKeywordInCall == R.SpaceAfterOperatorKeywordInCall &&
+           SpaceAfterOperatorKeywordInCall == 
+               R.SpaceAfterOperatorKeywordInCall &&
            SpaceAfterTemplateKeyword == R.SpaceAfterTemplateKeyword &&
            SpaceBeforeAssignmentOperators == R.SpaceBeforeAssignmentOperators &&
            SpaceBeforeCaseColon == R.SpaceBeforeCaseColon &&


-------------- next part --------------
A non-text attachment was scrubbed...
Name: D152443.529798.patch
Type: text/x-patch
Size: 2901 bytes
Desc: not available
URL: <http://lists.llvm.org/pipermail/cfe-commits/attachments/20230609/ee6c706b/attachment.bin>


More information about the cfe-commits mailing list