Author: Owen Pan Date: 2025-03-27T00:57:17-07:00 New Revision: b8a0558dea942b40f6cdcfaf9b6ba62d4140d693
URL: https://github.com/llvm/llvm-project/commit/b8a0558dea942b40f6cdcfaf9b6ba62d4140d693 DIFF: https://github.com/llvm/llvm-project/commit/b8a0558dea942b40f6cdcfaf9b6ba62d4140d693.diff LOG: [clang-format] Fix a regression on annotating template angles (#132885) Annotate the angles in `A<B != A>B` as template opener/closer as it's unlikely that they are less/greater-than operators in this context. Fix #132248 Added: Modified: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Removed: ################################################################################ diff --git a/clang/lib/Format/TokenAnnotator.cpp b/clang/lib/Format/TokenAnnotator.cpp index 01bf8c3778928..d87b3a6088bd8 100644 --- a/clang/lib/Format/TokenAnnotator.cpp +++ b/clang/lib/Format/TokenAnnotator.cpp @@ -253,8 +253,7 @@ class AnnotatingParser { // FIXME: This is getting out of hand, write a decent parser. if (MaybeAngles && InExpr && !Line.startsWith(tok::kw_template) && Prev.is(TT_BinaryOperator) && - (Prev.isOneOf(tok::pipepipe, tok::ampamp) || - Prev.getPrecedence() == prec::Equality)) { + Prev.isOneOf(tok::pipepipe, tok::ampamp)) { MaybeAngles = false; } if (Prev.isOneOf(tok::question, tok::colon) && !Style.isProto()) diff --git a/clang/unittests/Format/TokenAnnotatorTest.cpp b/clang/unittests/Format/TokenAnnotatorTest.cpp index 3480b55dcbae8..ac5e979aea071 100644 --- a/clang/unittests/Format/TokenAnnotatorTest.cpp +++ b/clang/unittests/Format/TokenAnnotatorTest.cpp @@ -720,8 +720,9 @@ TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { Tokens = annotate("return A < B != A > B;"); ASSERT_EQ(Tokens.size(), 10u) << Tokens; - EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); - EXPECT_TOKEN(Tokens[6], tok::greater, TT_BinaryOperator); + // FIXME: + // EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); + // EXPECT_TOKEN(Tokens[6], tok::greater, TT_BinaryOperator); Tokens = annotate("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); ASSERT_EQ(Tokens.size(), 27u) << Tokens; @@ -3836,6 +3837,16 @@ TEST_F(TokenAnnotatorTest, TemplateInstantiation) { ASSERT_EQ(Tokens.size(), 24u) << Tokens; EXPECT_TOKEN(Tokens[6], tok::less, TT_TemplateOpener); EXPECT_TOKEN(Tokens[18], tok::greater, TT_TemplateCloser); + + Tokens = annotate( + "std::uint16_t kMTU = std::conditional<\n" + " kTypeKind == KindA,\n" + " std::integral_constant<std::uint16_t, kIoSockMtu>>::type::value;"); + ASSERT_EQ(Tokens.size(), 30u) << Tokens; + EXPECT_TOKEN(Tokens[8], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[16], tok::less, TT_TemplateOpener); + EXPECT_TOKEN(Tokens[22], tok::greater, TT_TemplateCloser); + EXPECT_TOKEN(Tokens[23], tok::greater, TT_TemplateCloser); } TEST_F(TokenAnnotatorTest, VariableTemplate) { _______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits