Skip to content

Commit 9e50108

Browse files
author
Galen Elias
committed
More PR comment cleanup
1 parent df397a9 commit 9e50108

File tree

2 files changed

+22
-18
lines changed

2 files changed

+22
-18
lines changed

clang/lib/Format/UnwrappedLineFormatter.cpp

Lines changed: 19 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -631,11 +631,19 @@ class LineJoiner {
631631
unsigned Limit) {
632632
if (Limit == 0)
633633
return 0;
634-
if (I[1]->InPPDirective != (*I)->InPPDirective ||
635-
(I[1]->InPPDirective && I[1]->First->HasUnescapedNewline)) {
634+
assert(I[1]);
635+
const auto &L1 = *I[1];
636+
if (L1.InPPDirective != (*I)->InPPDirective ||
637+
(L1.InPPDirective && L1.First->HasUnescapedNewline)) {
636638
return 0;
637639
}
638-
if (I + 2 == E || I[2]->Type == LT_Invalid)
640+
641+
if (std::distance(I, E) <= 2)
642+
return 0;
643+
644+
assert(I[2]);
645+
const auto &L2 = *I[2];
646+
if (L2.Type == LT_Invalid)
639647
return 0;
640648

641649
Limit = limitConsideringMacros(I + 1, E, Limit);
@@ -645,13 +653,13 @@ class LineJoiner {
645653

646654
// Check if it's a namespace inside a namespace, and call recursively if so.
647655
// '3' is the sizes of the whitespace and closing brace for " _inner_ }".
648-
if (I[1]->First->is(tok::kw_namespace)) {
649-
if (I[1]->Last->is(tok::comment) || !Style.CompactNamespaces)
656+
if (L1.First->is(tok::kw_namespace)) {
657+
if (L1.Last->is(tok::comment) || !Style.CompactNamespaces)
650658
return 0;
651659

652-
assert(Limit >= I[1]->Last->TotalLength + 3);
653-
const unsigned InnerLimit = Limit - I[1]->Last->TotalLength - 3;
654-
const unsigned MergedLines = tryMergeNamespace(I + 1, E, InnerLimit);
660+
assert(Limit >= L1.Last->TotalLength + 3);
661+
const auto InnerLimit = Limit - L1.Last->TotalLength - 3;
662+
const auto MergedLines = tryMergeNamespace(I + 1, E, InnerLimit);
655663
if (MergedLines == 0)
656664
return 0;
657665
const auto N = MergedLines + 2;
@@ -672,11 +680,11 @@ class LineJoiner {
672680
// line.
673681

674682
// The line which is in the namespace should end with semicolon.
675-
if (I[1]->Last->isNot(tok::semi))
683+
if (L1.Last->isNot(tok::semi))
676684
return 0;
677685

678686
// Last, check that the third line starts with a closing brace.
679-
if (I[2]->First->isNot(tok::r_brace) || I[2]->First->MustBreakBefore)
687+
if (L2.First->isNot(tok::r_brace) || L2.First->MustBreakBefore)
680688
return 0;
681689

682690
// If so, merge all three lines.
@@ -987,7 +995,7 @@ class LineJoiner {
987995
SmallVectorImpl<AnnotatedLine *>::const_iterator E,
988996
unsigned Limit) {
989997
unsigned JoinedLength = 0;
990-
for (auto J = I + 1; J != E; ++J) {
998+
for (const auto *J = I + 1; J != E; ++J) {
991999
if ((*J)->First->MustBreakBefore)
9921000
return false;
9931001

clang/unittests/Format/FormatTest.cpp

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4484,7 +4484,7 @@ TEST_F(FormatTest, FormatsCompactNamespaces) {
44844484
"} // namespace A",
44854485
Style);
44864486

4487-
Style.ColumnLimit = 41;
4487+
Style.ColumnLimit = 40;
44884488
verifyFormat("namespace aaaaaaaaaa {\n"
44894489
"namespace bbbbbbbbbb {\n"
44904490
"}} // namespace aaaaaaaaaa::bbbbbbbbbb",
@@ -4505,13 +4505,9 @@ TEST_F(FormatTest, FormatsCompactNamespaces) {
45054505
"} // namespace aaaaaa",
45064506
Style);
45074507

4508-
verifyFormat("namespace a { namespace b { namespace c {\n"
4509-
"}}} // namespace a::b::c",
4510-
Style);
4511-
45124508
verifyFormat("namespace a { namespace b {\n"
4513-
"namespace cc {\n"
4514-
"}}} // namespace a::b::cc",
4509+
"namespace c {\n"
4510+
"}}} // namespace a::b::c",
45154511
Style);
45164512

45174513
Style.ColumnLimit = 80;

0 commit comments

Comments
 (0)