[clang] ef71383 - [clang-format] Distinguish logical and after bracket from reference
via cfe-commits
cfe-commits at lists.llvm.org
Fri Aug 12 20:54:45 PDT 2022
Author: jackh
Date: 2022-08-13T11:52:23+08:00
New Revision: ef71383b0cfbacdbebf495015f6ead5294bf7759
URL: https://github.com/llvm/llvm-project/commit/ef71383b0cfbacdbebf495015f6ead5294bf7759
DIFF: https://github.com/llvm/llvm-project/commit/ef71383b0cfbacdbebf495015f6ead5294bf7759.diff
LOG: [clang-format] Distinguish logical and after bracket from reference
Fix commit `b646f0955574` and remove redundant code.
Differential Revision: https://reviews.llvm.org/D131750
Added:
Modified:
clang/lib/Format/TokenAnnotator.cpp
clang/unittests/Format/FormatTest.cpp
clang/unittests/Format/TokenAnnotatorTest.cpp
Removed:
################################################################################
diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp
index ce49fd205425e..b0a1c691c771a 100644
--- a/clang/lib/Format/TokenAnnotator.cpp
+++ b/clang/lib/Format/TokenAnnotator.cpp
@@ -2365,25 +2365,6 @@ class AnnotatingParser {
!PrevToken->MatchingParen)
return TT_PointerOrReference;
- // For "} &&"
- if (PrevToken->is(tok::r_brace) && Tok.is(tok::ampamp)) {
- const FormatToken *MatchingLBrace = PrevToken->MatchingParen;
-
- // We check whether there is a TemplateCloser(">") to indicate it's a
- // template or not. If it's not a template, "&&" is likely a reference
- // operator.
- // struct {} &&ref = {};
- if (!MatchingLBrace)
- return TT_PointerOrReference;
- FormatToken *BeforeLBrace = MatchingLBrace->getPreviousNonComment();
- if (!BeforeLBrace || BeforeLBrace->isNot(TT_TemplateCloser))
- return TT_PointerOrReference;
-
- // If it is a template, "&&" is a binary operator.
- // enable_if<>{} && ...
- return TT_BinaryOperator;
- }
-
if (PrevToken->Tok.isLiteral() ||
PrevToken->isOneOf(tok::r_paren, tok::r_square, tok::kw_true,
tok::kw_false, tok::r_brace)) {
diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp
index d15c38f291ac2..ef68c528cb5c6 100644
--- a/clang/unittests/Format/FormatTest.cpp
+++ b/clang/unittests/Format/FormatTest.cpp
@@ -10474,6 +10474,7 @@ TEST_F(FormatTest, UnderstandsUsesOfStarAndAmp) {
verifyFormat("class {\n"
"}&& ptr = {};",
Style);
+ verifyFormat("bool b = 3 == int{3} && true;");
Style.PointerAlignment = FormatStyle::PAS_Middle;
verifyFormat("struct {\n"
diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp
index 9c3606f49a41b..8361a6c19085e 100644
--- a/clang/unittests/Format/TokenAnnotatorTest.cpp
+++ b/clang/unittests/Format/TokenAnnotatorTest.cpp
@@ -88,6 +88,10 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) {
EXPECT_EQ(Tokens.size(), 5u) << Tokens;
EXPECT_TOKEN(Tokens[1], tok::amp, TT_UnaryOperator);
+ Tokens = annotate("bool b = 3 == int{3} && true;\n");
+ EXPECT_EQ(Tokens.size(), 13u) << Tokens;
+ EXPECT_TOKEN(Tokens[9], tok::ampamp, TT_BinaryOperator);
+
Tokens = annotate("struct {\n"
"} *ptr;");
EXPECT_EQ(Tokens.size(), 7u) << Tokens;
More information about the cfe-commits
mailing list