[PATCH] D134853: [clang-format] Correctly annotate UDLs as OverloadedOperator
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Mon Oct 17 02:59:59 PDT 2022
owenpan added inline comments.
================
Comment at: clang/lib/Format/TokenAnnotator.cpp:1186-1199
+ tok::amp, tok::ampamp)) {
CurrentToken->Previous->setType(TT_OverloadedOperator);
}
+ // User defined literal without a space.
+ if (CurrentToken->Previous->is(tok::string_literal) &&
+ CurrentToken->Previous->TokenText.startswith("\"\"")) {
+ CurrentToken->Previous->setType(TT_OverloadedOperator);
----------------
We can simply check if the previous token starts with `""`.
================
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);
----------------
We need/should not annotate the suffix.
================
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);
----------------
IMO they are redundant as both `_a` and `_long_literal` are identifiers starting with an underscore.
================
Comment at: clang/unittests/Format/TokenAnnotatorTest.cpp:435
+ 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);
----------------
Delete.
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