File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -2889,6 +2889,7 @@ void UnwrappedLineParser::parseForOrWhileLoop() {
2889
2889
if (FormatTok->is (tok::l_paren))
2890
2890
parseParens ();
2891
2891
2892
+ handleAttributes ();
2892
2893
parseLoopBody (KeepBraces, /* WrapRightBrace=*/ true );
2893
2894
}
2894
2895
Original file line number Diff line number Diff line change @@ -23846,6 +23846,22 @@ TEST_F(FormatTest, LikelyUnlikely) {
23846
23846
" return 29;\n",
23847
23847
Style);
23848
23848
23849
+ verifyFormat("while (limit > 0) [[unlikely]] {\n"
23850
+ " --limit;\n"
23851
+ "}",
23852
+ Style);
23853
+ verifyFormat("for (auto &limit : limits) [[likely]] {\n"
23854
+ " --limit;\n"
23855
+ "}",
23856
+ Style);
23857
+
23858
+ verifyFormat("for (auto &limit : limits) [[unlikely]]\n"
23859
+ " --limit;",
23860
+ Style);
23861
+ verifyFormat("while (limit > 0) [[likely]]\n"
23862
+ " --limit;",
23863
+ Style);
23864
+
23849
23865
Style.AttributeMacros.push_back("UNLIKELY");
23850
23866
Style.AttributeMacros.push_back("LIKELY");
23851
23867
verifyFormat("if (argc > 5) UNLIKELY\n"
@@ -23874,6 +23890,22 @@ TEST_F(FormatTest, LikelyUnlikely) {
23874
23890
" return 42;\n"
23875
23891
"}\n",
23876
23892
Style);
23893
+
23894
+ verifyFormat("for (auto &limit : limits) UNLIKELY {\n"
23895
+ " --limit;\n"
23896
+ "}",
23897
+ Style);
23898
+ verifyFormat("while (limit > 0) LIKELY {\n"
23899
+ " --limit;\n"
23900
+ "}",
23901
+ Style);
23902
+
23903
+ verifyFormat("while (limit > 0) UNLIKELY\n"
23904
+ " --limit;",
23905
+ Style);
23906
+ verifyFormat("for (auto &limit : limits) LIKELY\n"
23907
+ " --limit;",
23908
+ Style);
23877
23909
}
23878
23910
23879
23911
TEST_F(FormatTest, PenaltyIndentedWhitespace) {
You can’t perform that action at this time.
0 commit comments