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

Emilia Dreamer via Phabricator via cfe-commits cfe-commits at lists.llvm.org
Tue Oct 18 03:46:47 PDT 2022


rymiel marked 2 inline comments as done.
rymiel added inline comments.


================
Comment at: clang/lib/Format/TokenAnnotator.cpp:2126
       return false;
 
     FormatToken *LeftOfParens = Tok.MatchingParen->getPreviousNonComment();
----------------
owenpan wrote:
> Perhaps add:
> ```
>     if (Tok.MatchingParen->is(TT_OverloadedOperatorLParen))
>       return false;
> ```
Note that in testing, adding `isNot(TT_Unknown)` did not cause any issues in tests, but that change felt a little too drastic


================
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);
----------------
owenpan wrote:
> 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.
Oh, you are right; I did not notice the extra check which disallows identifiers in front of casts


================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:415-423
+  Tokens = annotate("x.operator\"\"_long_literal()");
+  ASSERT_EQ(Tokens.size(), 7u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
+  EXPECT_TOKEN(Tokens[4], tok::l_paren, TT_OverloadedOperatorLParen);
+  Tokens = annotate("x.operator\"\" _long_literal()");
+  ASSERT_EQ(Tokens.size(), 8u) << Tokens;
+  EXPECT_TOKEN(Tokens[3], tok::string_literal, TT_OverloadedOperator);
----------------
owenpan wrote:
> IMO they are redundant as both `_a` and `_long_literal` are identifiers starting with an underscore.
I wanted to avoid all the tests being single-character names, as "single-character name" was sort of an issue for one format bug; but actually this isn't even single character anyway so you are right


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