@@ -1355,18 +1355,20 @@ TEST_F(FormatTest, FormatIfWithoutCompoundStatementButElseWith) {
1355
1355
}
1356
1356
1357
1357
TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
1358
+ verifyFormat("while (true)\n"
1359
+ " ;");
1360
+ verifyFormat("for (;;)\n"
1361
+ " ;");
1362
+
1358
1363
FormatStyle AllowsMergedLoops = getLLVMStyle();
1359
1364
AllowsMergedLoops.AllowShortLoopsOnASingleLine = true;
1365
+
1360
1366
verifyFormat("while (true) continue;", AllowsMergedLoops);
1361
1367
verifyFormat("for (;;) continue;", AllowsMergedLoops);
1362
1368
verifyFormat("for (int &v : vec) v *= 2;", AllowsMergedLoops);
1363
1369
verifyFormat("BOOST_FOREACH (int &v, vec) v *= 2;", AllowsMergedLoops);
1364
- verifyFormat("while (true)\n"
1365
- " ;",
1366
- AllowsMergedLoops);
1367
- verifyFormat("for (;;)\n"
1368
- " ;",
1369
- AllowsMergedLoops);
1370
+ verifyFormat("while (true);", AllowsMergedLoops);
1371
+ verifyFormat("for (;;);", AllowsMergedLoops);
1370
1372
verifyFormat("for (;;)\n"
1371
1373
" for (;;) continue;",
1372
1374
AllowsMergedLoops);
@@ -1404,6 +1406,7 @@ TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
1404
1406
" a++;\n"
1405
1407
"while (true);",
1406
1408
AllowsMergedLoops);
1409
+
1407
1410
// Without braces labels are interpreted differently.
1408
1411
verifyFormat("{\n"
1409
1412
" do\n"
@@ -1412,6 +1415,17 @@ TEST_F(FormatTest, FormatLoopsWithoutCompoundStatement) {
1412
1415
" while (true);\n"
1413
1416
"}",
1414
1417
AllowsMergedLoops);
1418
+
1419
+ // Don't merge if there are comments before the null statement.
1420
+ verifyFormat("while (1) //\n"
1421
+ " ;",
1422
+ AllowsMergedLoops);
1423
+ verifyFormat("for (;;) /**/\n"
1424
+ " ;",
1425
+ AllowsMergedLoops);
1426
+ verifyFormat("while (true) /**/\n"
1427
+ " ;",
1428
+ "while (true) /**/;", AllowsMergedLoops);
1415
1429
}
1416
1430
1417
1431
TEST_F(FormatTest, FormatShortBracedStatements) {
0 commit comments