llvmorg-github-actions[bot] wrote:
<!--LLVM PR SUMMARY COMMENT--> @llvm/pr-subscribers-clang-format Author: owenca (owenca) <details> <summary>Changes</summary> This reverts e99e343dfdb2b1b490789a7bcba6d646a4824f15 (#<!-- -->199112). Fixes #<!-- -->199027 --- Full diff: https://github.com/llvm/llvm-project/pull/206300.diff 3 Files Affected: - (modified) clang/lib/Format/TokenAnnotator.cpp (+2-8) - (modified) clang/unittests/Format/FormatTest.cpp (+1-1) - (modified) clang/unittests/Format/TokenAnnotatorTest.cpp (+5-4) ``````````diff diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 634143d843c3b..550beb96396a9 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -2500,6 +2500,8 @@ class AnnotatingParser { Current.setType(TT_Unknown); } else { Current.setType(TT_ConditionalExpr); + if (IsCpp) + Contexts.back().IsExpression = true; } } else if (Current.isBinaryOperator() && (!Current.Previous || Current.Previous->isNot(tok::l_square)) && @@ -3040,14 +3042,6 @@ class AnnotatingParser { if (Style.isCSharp() && Tok.is(tok::ampamp)) return TT_BinaryOperator; - // The keyword `and` (tok::ampamp) is always binary, never a declarator. - // Not extended to `bitand` (tok::amp), which can be a reference. - if (Tok.is(tok::ampamp)) { - const auto *Info = Tok.Tok.getIdentifierInfo(); - if (Info && Info->isCPlusPlusOperatorKeyword()) - return TT_BinaryOperator; - } - if (Style.isVerilog()) { // In Verilog, `*` can only be a binary operator. `&` can be either unary // or binary. `*` also includes `*>` in module path declarations in diff --git a/clang/unittests/Format/FormatTest.cpp b/clang/unittests/Format/FormatTest.cpp index c42cc147cf21e..896d71181e2b3 100644 --- a/clang/unittests/Format/FormatTest.cpp +++ b/clang/unittests/Format/FormatTest.cpp @@ -22558,7 +22558,7 @@ TEST_F(FormatTest, DoNotCrashOnInvalidInput) { "LY52: ! [internal]"); verifyNoCrash("operator foo *;"); verifyNoCrash( - " #xxxx??x<xxxxxxx||??x<xxxxxxx and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); + "#xxxx??x<xxxxxxx||??x<xxxxxxx and xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"); } TEST_F(FormatTest, FormatsTableGenCode) { diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index b6300e2ca78ba..9dec5e05d8aad 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -445,6 +445,11 @@ TEST_F(TokenAnnotatorTest, UnderstandsUsesOfStarAndAmp) { ASSERT_EQ(Tokens.size(), 30u) << Tokens; EXPECT_TOKEN(Tokens[18], tok::star, TT_PointerOrReference); EXPECT_TOKEN(Tokens[19], tok::identifier, TT_StartOfName); + + Tokens = annotate("foo ? a < b && c : bar"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[5], tok::star, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[6], tok::identifier, TT_Unknown); // Not TT_StartOfName } TEST_F(TokenAnnotatorTest, UnderstandsUsesOfPlusAndMinus) { @@ -4198,10 +4203,6 @@ TEST_F(TokenAnnotatorTest, CppAltOperatorKeywords) { ASSERT_EQ(Tokens.size(), 7u) << Tokens; EXPECT_TOKEN(Tokens[3], tok::caretequal, TT_BinaryOperator); - Tokens = annotate("if (a and b) {}"); - ASSERT_EQ(Tokens.size(), 9u) << Tokens; - EXPECT_TOKEN(Tokens[3], tok::ampamp, TT_BinaryOperator); - const auto StyleC = getLLVMStyle(FormatStyle::LK_C); Tokens = annotate("xor = foo;", StyleC); `````````` </details> https://github.com/llvm/llvm-project/pull/206300 _______________________________________________ cfe-commits mailing list [email protected] https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits
