This revision was landed with ongoing or failed builds. This revision was automatically updated to reflect the committed changes. Closed by commit rGe4d3e8880239: [clang-format] Don't allow template to be preceded by closing brace (authored by rymiel).
Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D150629/new/ https://reviews.llvm.org/D150629 Files: clang/lib/Format/TokenAnnotator.cpp clang/unittests/Format/FormatTest.cpp clang/unittests/Format/TokenAnnotatorTest.cpp Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -480,6 +480,23 @@ EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { + auto Tokens = annotate("return a < b && c > d;"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[6], tok::greater, TT_BinaryOperator); + + Tokens = annotate("a < 0 ? b : a > 0 ? c : d;"); + ASSERT_EQ(Tokens.size(), 15u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[7], tok::greater, TT_BinaryOperator); + + Tokens = annotate("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); + ASSERT_EQ(Tokens.size(), 27u) << Tokens; + EXPECT_TOKEN(Tokens[7], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator); +} + TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) { FormatStyle Style = getLLVMStyle(); Style.WhitespaceSensitiveMacros.push_back("FOO"); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10679,6 +10679,7 @@ // Not template parameters. verifyFormat("return a < b && c > d;"); verifyFormat("a < 0 ? b : a > 0 ? c : d;"); + verifyFormat("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); verifyFormat("void f() {\n" " while (a < b && c > d) {\n" " }\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -144,6 +144,8 @@ if (Previous.Previous) { if (Previous.Previous->Tok.isLiteral()) return false; + if (Previous.Previous->is(tok::r_brace)) + return false; if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && (!Previous.Previous->MatchingParen || !Previous.Previous->MatchingParen->is(
Index: clang/unittests/Format/TokenAnnotatorTest.cpp =================================================================== --- clang/unittests/Format/TokenAnnotatorTest.cpp +++ clang/unittests/Format/TokenAnnotatorTest.cpp @@ -480,6 +480,23 @@ EXPECT_TOKEN(Tokens[8], tok::greater, TT_BinaryOperator); } +TEST_F(TokenAnnotatorTest, UnderstandsNonTemplateAngleBrackets) { + auto Tokens = annotate("return a < b && c > d;"); + ASSERT_EQ(Tokens.size(), 10u) << Tokens; + EXPECT_TOKEN(Tokens[2], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[6], tok::greater, TT_BinaryOperator); + + Tokens = annotate("a < 0 ? b : a > 0 ? c : d;"); + ASSERT_EQ(Tokens.size(), 15u) << Tokens; + EXPECT_TOKEN(Tokens[1], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[7], tok::greater, TT_BinaryOperator); + + Tokens = annotate("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); + ASSERT_EQ(Tokens.size(), 27u) << Tokens; + EXPECT_TOKEN(Tokens[7], tok::less, TT_BinaryOperator); + EXPECT_TOKEN(Tokens[20], tok::greater, TT_BinaryOperator); +} + TEST_F(TokenAnnotatorTest, UnderstandsWhitespaceSensitiveMacros) { FormatStyle Style = getLLVMStyle(); Style.WhitespaceSensitiveMacros.push_back("FOO"); Index: clang/unittests/Format/FormatTest.cpp =================================================================== --- clang/unittests/Format/FormatTest.cpp +++ clang/unittests/Format/FormatTest.cpp @@ -10679,6 +10679,7 @@ // Not template parameters. verifyFormat("return a < b && c > d;"); verifyFormat("a < 0 ? b : a > 0 ? c : d;"); + verifyFormat("ratio{-1, 2} < ratio{-1, 3} == -1 / 3 > -1 / 2;"); verifyFormat("void f() {\n" " while (a < b && c > d) {\n" " }\n" Index: clang/lib/Format/TokenAnnotator.cpp =================================================================== --- clang/lib/Format/TokenAnnotator.cpp +++ clang/lib/Format/TokenAnnotator.cpp @@ -144,6 +144,8 @@ if (Previous.Previous) { if (Previous.Previous->Tok.isLiteral()) return false; + if (Previous.Previous->is(tok::r_brace)) + return false; if (Previous.Previous->is(tok::r_paren) && Contexts.size() > 1 && (!Previous.Previous->MatchingParen || !Previous.Previous->MatchingParen->is(
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits