[PATCH] D134853: [clang-format] Correctly annotate UDLs as OverloadedOperator

Owen Pan via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 18 02:51:15 PDT 2022


owenpan added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:2126
       return false;
 
     FormatToken *LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
----------------
Perhaps add:
```
    if (Tok.MatchingParen->is(TT_OverloadedOperatorLParen))
      return false;
```


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:413
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::identifier, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[5], tok::l_paren, TT_OverloadedOperatorLParen);
----------------
rymiel wrote:
> owenpan wrote:
> > We need/should not annotate the suffix.
> Unless I change the logic in `rParenEndsCast`, the suffix does need to be an OverloadedOperator, since it goes off of the token immediately before left paren (https://reviews.llvm.org/D134853#3822842)
After we annotate `""` as `TT_OverloadedOperator`, `rParenEndsCast()` returns false, at least for your test cases and the example in https://github.com/llvm/llvm-project/issues/58035. If you can come up with test cases that still confuses `rParenEndsCast()`, we can add a simple check near the beginning of `rParenEndsCast()`. See line 2126 above.


Repository:
  rG LLVM Github Monorepo

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

https://reviews.llvm.org/D134853



More information about the cfe-commits mailing list