[PATCH] D11177: clang-format: Fix return type breaking with operator overload functions

Birunthan Mohanathas birunthan at mohanathas.com
Wed Jul 15 11:35:48 PDT 2015


poiru added inline comments.

================
Comment at: lib/Format/TokenAnnotator.cpp:509
@@ +508,3 @@
+          Tok->Previous->MatchingParen->Previous &&
+          Tok->Previous->MatchingParen->Previous->is(tok::kw_operator)) {
+        Tok->Previous->MatchingParen->Type = TT_OverloadedOperator;
----------------
djasper wrote:
> Why is this last check important? To not mark operator()()()? Is that important?
Probably not, removed.

================
Comment at: lib/Format/TokenAnnotator.cpp:1478
@@ -1470,1 +1477,3 @@
+      return false;
+    while (Next && !Next->is(TT_OverloadedOperatorLParen))
       Next = Next->Next;
----------------
djasper wrote:
> What kinds of tokens do you expect to consume here? Would it be better to be more strict, i.e. consume exactly an operator, "new", "delete", "()" and such?
Done.

================
Comment at: lib/Format/TokenAnnotator.cpp:1492
@@ +1491,3 @@
+          Next = Next->Next;
+          while (Next && !Next->is(TT_OverloadedOperatorLParen))
+            Next = Next->Next;
----------------
djasper wrote:
> This is very similar to the above. What are the exact differences (maybe add a comment)? Could we factor some of this out into a local function or a lambda?
Done.

================
Comment at: lib/Format/TokenAnnotator.cpp:2187
@@ -2161,1 +2186,3 @@
     return true;
+  if (Right.is(tok::kw_operator))
+    return !Left.is(tok::coloncolon);
----------------
djasper wrote:
> I think this is incorrect as we currently break after the coloncolon if a nested name specifier has to be split, e.g.:
> 
>   void AssumeThisIsAVeryLongTypeOrSetASmallColumnLimit::
>       operator+() {
>   }
> 
Removed this bit, thanks.


http://reviews.llvm.org/D11177







More information about the cfe-commits mailing list