forked from OSchip/llvm-project
[clang-format] Distinguish logical and after bracket from reference
Fix commit `b646f0955574` and remove redundant code. Differential Revision: https://reviews.llvm.org/D131750
This commit is contained in:
parent
b12aa497cd
commit
ef71383b0c
|
@ -2365,25 +2365,6 @@ private:
|
|||
!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)) {
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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;
|
||||
|
|
Loading…
Reference in New Issue