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

2023-06-11 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D152443#4412069 , @KitsuneAlex 
wrote:

> This revision of the diff changes the names of the new style options to 
> **SpaceAfterOperatorOverload** and **SpaceAfterOperatorCall**, which 
> clarifies their scope a lot better i think.
> I also rewrote the logic to apply formatting that fits exactly what their 
> name implies respectively,
> the new tests i added should cover all common use cases (except i forgot some 
> again).

Two cases missing: `operator==()` (Calling within a class), and what happens 
when taking the address `==`? (With and without qualification.)




Comment at: clang/unittests/Format/FormatTest.cpp:22916
+  verifyFormat("foo.operator==();", Style);
+  verifyFormat("foo.Foo::operator==();", Style);
+  verifyFormat("foo->operator==();", Style);

Nice to check for that too!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-06-11 Thread Alexander Hinze via Phabricator via cfe-commits
KitsuneAlex updated this revision to Diff 530303.
KitsuneAlex marked 2 inline comments as done.
KitsuneAlex removed reviewers: lattner, craig.topper, RKSimon, respindola, 
rymiel, owenpan.
KitsuneAlex added a comment.
Herald added reviewers: rymiel, owenpan.

This revision of the diff changes the names of the new style options to 
**SpaceAfterOperatorOverload** and **SpaceAfterOperatorCall**, which clarifies 
their scope a lot better i think.
I also rewrote the logic to apply formatting that fits exactly what their name 
implies respectively,
the new tests i added should cover all common use cases (except i forgot some 
again).


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22901,8 +22901,43 @@
Spaces);
 }
 
+TEST_F(FormatTest, SpaceAfterOperatorOverload) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("bool operator==();", Style);
+  verifyFormat("bool Foo::operator==();", Style);
+  verifyFormat("foo.operator==();", Style);
+  verifyFormat("foo.Foo::operator==();", Style);
+  verifyFormat("foo->operator==();", Style);
+  verifyFormat("foo->Foo::operator==();", Style);
+  Style.SpaceAfterOperatorOverload = true;
+  verifyFormat("bool operator ==();", Style);
+  verifyFormat("bool Foo::operator ==();", Style);
+  verifyFormat("foo.operator==();", Style);
+  verifyFormat("foo.Foo::operator==();", Style);
+  verifyFormat("foo->operator==();", Style);
+  verifyFormat("foo->Foo::operator==();", Style);
+}
+
+TEST_F(FormatTest, SpaceAfterOperatorCall) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("bool operator==();", Style);
+  verifyFormat("bool Foo::operator==();", Style);
+  verifyFormat("foo.operator==();", Style);
+  verifyFormat("foo.Foo::operator==();", Style);
+  verifyFormat("foo->operator==();", Style);
+  verifyFormat("foo->Foo::operator==();", Style);
+  Style.SpaceAfterOperatorCall = true;
+  verifyFormat("bool operator==();", Style);
+  verifyFormat("bool Foo::operator==();", Style);
+  verifyFormat("foo.operator ==();", Style);
+  verifyFormat("foo.Foo::operator ==();", Style);
+  verifyFormat("foo->operator ==();", Style);
+  verifyFormat("foo->Foo::operator ==();", Style);
+}
+
 TEST_F(FormatTest, SpaceAfterTemplateKeyword) {
   FormatStyle Style = getLLVMStyle();
+  verifyFormat("template  void foo();", Style);
   Style.SpaceAfterTemplateKeyword = false;
   verifyFormat("template void foo();", Style);
 }
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -183,6 +183,8 @@
   CHECK_PARSE_BOOL(SpacesInContainerLiterals);
   CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
+  CHECK_PARSE_BOOL(SpaceAfterOperatorOverload);
+  CHECK_PARSE_BOOL(SpaceAfterOperatorCall);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceAfterLogicalNot);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -4200,9 +4200,21 @@
 // Space in __attribute__((attr)) ::type.
 if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon))
   return true;
-
-if (Left.is(tok::kw_operator))
-  return Right.is(tok::coloncolon);
+if (Left.is(tok::kw_operator)) {
+  if (Left.hasWhitespaceBefore())
+return Style.SpaceAfterOperatorOverload || Right.is(tok::coloncolon);
+  if (!Left.Previous)
+return Right.is(tok::coloncolon);
+  FormatToken const *Previous = Left.Previous;
+  while (Previous) {
+if (!Previous->hasWhitespaceBefore()) {
+  Previous = Previous->Previous;
+  continue;
+}
+return Style.SpaceAfterOperatorOverload || Right.is(tok::coloncolon);
+  }
+  return Style.SpaceAfterOperatorCall || Right.is(tok::coloncolon);
+}
 if (Right.is(tok::l_brace) && Right.is(BK_BracedInit) &&
 !Left.opensScope() && Style.SpaceBeforeCpp11BracedList) {
   return true;
Index: clang/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1000,6 +1000,9 @@
 IO.mapOptional("SortUsingDeclarations", 

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

2023-06-09 Thread Alexander Hinze via Phabricator via cfe-commits
KitsuneAlex added a comment.

In D152443#4408991 , @MyDeveloperDay 
wrote:

> In D152443#4407438 , @KitsuneAlex 
> wrote:
>
>> I had some issues with Git there because i messed up a merge, so the diff 
>> was bad. Here's the proper diff.
>
>
>
>> NOTE: Clang-Format Team Automated Review Comment
>
> keeps you honest right!

Yes, i was referring to the fact that the previous diff was only 30% of my 
intended changes if you look at the changed files, which was caused by an 
unsmart local merge on my end.
That's why my following diff corrected the formatting.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-06-09 Thread Björn Schäpers via Phabricator via cfe-commits
HazardyKnusperkeks added a comment.

In D152443#4407331 , @KitsuneAlex 
wrote:

> Applied all suggested changes and added a suiting option for aformentioned 
> edge-case for call expressions.
> Also added the missing release notes to the apropriate section.

Please mark comments as done, if you think they are done.




Comment at: clang/docs/ClangFormatStyleOptions.rst:4709
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 17` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the 'operator' keyword.

MyDeveloperDay wrote:
> could we use something like `SpaceAfterOperatorDeclaration` to differentiate
But it also applies to the definition?

Keyword seems to be wrong too, if we have a second option for the calls...

I currently have no recommendations for the naming.



Comment at: clang/lib/Format/TokenAnnotator.cpp:4206
+  if (Left.Previous &&
+  Left.Previous->isOneOf(tok::coloncolon, tok::period)) {
+return Style.SpaceAfterOperatorKeywordInCall ||

`bool Foo::operator==() = default;`?

Please add a test. :)



Comment at: clang/unittests/Format/FormatTest.cpp:22915
+  verifyFormat("foo.Foo::operator==();", Style);
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);

Can you add an empty line, so that the 2 blocks are visually separated?



Comment at: clang/unittests/Format/FormatTest.cpp:22916
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);
+  verifyFormat("foo.Foo::operator ==();", Style);

MyDeveloperDay wrote:
> I assume I could have `foo->operator ==();`
Of course you can. :)


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added a comment.

In D152443#4407438 , @KitsuneAlex 
wrote:

> I had some issues with Git there because i messed up a merge, so the diff was 
> bad. Here's the proper diff.



> NOTE: Clang-Format Team Automated Review Comment

keep you honest right!


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-06-09 Thread MyDeveloperDay via Phabricator via cfe-commits
MyDeveloperDay added inline comments.



Comment at: clang/docs/ClangFormatStyleOptions.rst:4709
+
+**SpaceAfterOperatorKeyword** (``Boolean``) :versionbadge:`clang-format 17` 
:ref:`¶ `
+  If ``true``, a space will be inserted after the 'operator' keyword.

could we use something like `SpaceAfterOperatorDeclaration` to differentiate



Comment at: clang/docs/ClangFormatStyleOptions.rst:4719
+
+**SpaceAfterOperatorKeywordInCall** (``Boolean``) :versionbadge:`clang-format 
17` :ref:`¶ `
+  If ``true``, a space will be inserted after the 'operator' keyword in a call 
expression.

I'm not going to lie I'm not a fan of `SpaceAfterOperatorKeywordInCall` as an 
option name, any other suggestions for a name?



Comment at: clang/lib/Format/TokenAnnotator.cpp:3762
   }
+
   // co_await (x), co_yield (x), co_return (x)

kind of unrelated change?



Comment at: clang/unittests/Format/FormatTest.cpp:22916
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);
+  verifyFormat("foo.Foo::operator ==();", Style);

I assume I could have `foo->operator ==();`


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

___
cfe-commits mailing list
cfe-commits@lists.llvm.org
https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits


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

2023-06-08 Thread Alexander Hinze via Phabricator via cfe-commits
KitsuneAlex updated this revision to Diff 529804.
KitsuneAlex added a comment.

Clean up the formatting with clang-format.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22901,8 +22901,25 @@
Spaces);
 }
 
+TEST_F(FormatTest, SpaceAfterOperatorKeyword) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("bool operator==();", Style);
+  Style.SpaceAfterOperatorKeyword = true;
+  verifyFormat("bool operator ==();", Style);
+}
+
+TEST_F(FormatTest, SpaceAfterOperatorKeywordInCall) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("foo.operator==();", Style);
+  verifyFormat("foo.Foo::operator==();", Style);
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);
+  verifyFormat("foo.Foo::operator ==();", Style);
+}
+
 TEST_F(FormatTest, SpaceAfterTemplateKeyword) {
   FormatStyle Style = getLLVMStyle();
+  verifyFormat("template  void foo();", Style);
   Style.SpaceAfterTemplateKeyword = false;
   verifyFormat("template void foo();", Style);
 }
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -183,6 +183,8 @@
   CHECK_PARSE_BOOL(SpacesInContainerLiterals);
   CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
+  CHECK_PARSE_BOOL(SpaceAfterOperatorKeyword);
+  CHECK_PARSE_BOOL(SpaceAfterOperatorKeywordInCall);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceAfterLogicalNot);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3759,6 +3759,7 @@
   Left.Previous->is(tok::kw_operator)) {
 return false;
   }
+
   // co_await (x), co_yield (x), co_return (x)
   if (Left.isOneOf(tok::kw_co_await, tok::kw_co_yield, tok::kw_co_return) &&
   !Right.isOneOf(tok::semi, tok::r_paren)) {
@@ -4200,9 +4201,14 @@
 // Space in __attribute__((attr)) ::type.
 if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon))
   return true;
-
-if (Left.is(tok::kw_operator))
-  return Right.is(tok::coloncolon);
+if (Left.is(tok::kw_operator)) {
+  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/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1000,6 +1000,10 @@
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
+IO.mapOptional("SpaceAfterOperatorKeyword",
+   Style.SpaceAfterOperatorKeyword);
+IO.mapOptional("SpaceAfterOperatorKeywordInCall",
+   Style.SpaceAfterOperatorKeywordInCall);
 IO.mapOptional("SpaceAfterTemplateKeyword",
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceAroundPointerQualifiers",
@@ -1439,6 +1443,8 @@
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
   LLVMStyle.SpaceAfterCStyleCast = false;
   LLVMStyle.SpaceAfterLogicalNot = false;
+  LLVMStyle.SpaceAfterOperatorKeyword = false;
+  LLVMStyle.SpaceAfterOperatorKeywordInCall = false;
   LLVMStyle.SpaceAfterTemplateKeyword = true;
   LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
   LLVMStyle.SpaceBeforeCaseColon = false;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3692,6 +3692,23 @@
   /// \version 9
   bool SpaceAfterLogicalNot;
 
+  /// If \c true, a space will be inserted after the 'operator' keyword.
+  /// \code
+  ///true:   

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

2023-06-08 Thread Alexander Hinze via Phabricator via cfe-commits
KitsuneAlex updated this revision to Diff 529799.
KitsuneAlex added a comment.

I had some issues with Git there because i messed up a merge, so the diff was 
bad. Here's the proper diff.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D152443

Files:
  clang/docs/ClangFormatStyleOptions.rst
  clang/docs/ReleaseNotes.rst
  clang/include/clang/Format/Format.h
  clang/lib/Format/Format.cpp
  clang/lib/Format/TokenAnnotator.cpp
  clang/unittests/Format/ConfigParseTest.cpp
  clang/unittests/Format/FormatTest.cpp

Index: clang/unittests/Format/FormatTest.cpp
===
--- clang/unittests/Format/FormatTest.cpp
+++ clang/unittests/Format/FormatTest.cpp
@@ -22901,8 +22901,25 @@
Spaces);
 }
 
+TEST_F(FormatTest, SpaceAfterOperatorKeyword) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("bool operator==();", Style);
+  Style.SpaceAfterOperatorKeyword = true;
+  verifyFormat("bool operator ==();", Style);
+}
+
+TEST_F(FormatTest, SpaceAfterOperatorKeywordInCall) {
+  FormatStyle Style = getLLVMStyle();
+  verifyFormat("foo.operator==();", Style);
+  verifyFormat("foo.Foo::operator==();", Style);
+  Style.SpaceAfterOperatorKeywordInCall = true;
+  verifyFormat("foo.operator ==();", Style);
+  verifyFormat("foo.Foo::operator ==();", Style);
+}
+
 TEST_F(FormatTest, SpaceAfterTemplateKeyword) {
   FormatStyle Style = getLLVMStyle();
+  verifyFormat("template  void foo();", Style);
   Style.SpaceAfterTemplateKeyword = false;
   verifyFormat("template void foo();", Style);
 }
Index: clang/unittests/Format/ConfigParseTest.cpp
===
--- clang/unittests/Format/ConfigParseTest.cpp
+++ clang/unittests/Format/ConfigParseTest.cpp
@@ -183,6 +183,8 @@
   CHECK_PARSE_BOOL(SpacesInContainerLiterals);
   CHECK_PARSE_BOOL(SpacesInCStyleCastParentheses);
   CHECK_PARSE_BOOL(SpaceAfterCStyleCast);
+  CHECK_PARSE_BOOL(SpaceAfterOperatorKeyword);
+  CHECK_PARSE_BOOL(SpaceAfterOperatorKeywordInCall);
   CHECK_PARSE_BOOL(SpaceAfterTemplateKeyword);
   CHECK_PARSE_BOOL(SpaceAfterLogicalNot);
   CHECK_PARSE_BOOL(SpaceBeforeAssignmentOperators);
Index: clang/lib/Format/TokenAnnotator.cpp
===
--- clang/lib/Format/TokenAnnotator.cpp
+++ clang/lib/Format/TokenAnnotator.cpp
@@ -3759,6 +3759,7 @@
   Left.Previous->is(tok::kw_operator)) {
 return false;
   }
+
   // co_await (x), co_yield (x), co_return (x)
   if (Left.isOneOf(tok::kw_co_await, tok::kw_co_yield, tok::kw_co_return) &&
   !Right.isOneOf(tok::semi, tok::r_paren)) {
@@ -4200,9 +4201,13 @@
 // Space in __attribute__((attr)) ::type.
 if (Left.is(TT_AttributeParen) && Right.is(tok::coloncolon))
   return true;
-
-if (Left.is(tok::kw_operator))
-  return Right.is(tok::coloncolon);
+if (Left.is(tok::kw_operator)) {
+  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/lib/Format/Format.cpp
===
--- clang/lib/Format/Format.cpp
+++ clang/lib/Format/Format.cpp
@@ -1000,6 +1000,10 @@
 IO.mapOptional("SortUsingDeclarations", Style.SortUsingDeclarations);
 IO.mapOptional("SpaceAfterCStyleCast", Style.SpaceAfterCStyleCast);
 IO.mapOptional("SpaceAfterLogicalNot", Style.SpaceAfterLogicalNot);
+IO.mapOptional("SpaceAfterOperatorKeyword",
+   Style.SpaceAfterOperatorKeyword);
+IO.mapOptional("SpaceAfterOperatorKeywordInCall",
+   Style.SpaceAfterOperatorKeywordInCall);
 IO.mapOptional("SpaceAfterTemplateKeyword",
Style.SpaceAfterTemplateKeyword);
 IO.mapOptional("SpaceAroundPointerQualifiers",
@@ -1439,6 +1443,8 @@
   LLVMStyle.SortUsingDeclarations = FormatStyle::SUD_LexicographicNumeric;
   LLVMStyle.SpaceAfterCStyleCast = false;
   LLVMStyle.SpaceAfterLogicalNot = false;
+  LLVMStyle.SpaceAfterOperatorKeyword = false;
+  LLVMStyle.SpaceAfterOperatorKeywordInCall = false;
   LLVMStyle.SpaceAfterTemplateKeyword = true;
   LLVMStyle.SpaceAroundPointerQualifiers = FormatStyle::SAPQ_Default;
   LLVMStyle.SpaceBeforeCaseColon = false;
Index: clang/include/clang/Format/Format.h
===
--- clang/include/clang/Format/Format.h
+++ clang/include/clang/Format/Format.h
@@ -3692,6 +3692,24 @@
   /// \version 9
   bool SpaceAfterLogicalNot;
 
+  /// If \c true, a space will be inserted after the 'operator' 

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

2023-06-08 Thread Alexander Hinze via Phabricator via cfe-commits
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 &&


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