@@ -368,7 +368,8 @@ class LineJoiner {
368368 if (TheLine->Last ->is (tok::l_brace)) {
369369 if (Style.AllowShortNamespacesOnASingleLine &&
370370 TheLine->First ->is (tok::kw_namespace)) {
371- if (unsigned result = tryMergeNamespace (I, E, Limit))
371+ unsigned result = tryMergeNamespace (I, E, Limit);
372+ if (result > 0 )
372373 return result;
373374 }
374375 }
@@ -643,26 +644,27 @@ class LineJoiner {
643644 if (!nextTwoLinesFitInto (I, Limit))
644645 return 0 ;
645646
646- // Check if it's a namespace inside a namespace, and call recursively if so
647+ // Check if it's a namespace inside a namespace, and call recursively if so.
647648 // '3' is the sizes of the whitespace and closing brace for " _inner_ }".
648649 if (I[1 ]->First ->is (tok::kw_namespace)) {
649- if (I[1 ]->Last ->is (TT_LineComment ))
650+ if (I[1 ]->Last ->is (tok::comment ))
650651 return 0 ;
651652
652653 const unsigned InnerLimit = Limit - I[1 ]->Last ->TotalLength - 3 ;
653654 const unsigned MergedLines = tryMergeNamespace (I + 1 , E, InnerLimit);
654655 if (!MergedLines)
655656 return 0 ;
657+ const auto N = MergedLines + 2 ;
656658 // Check if there is even a line after the inner result.
657- if (std::distance (I, E) <= MergedLines + 2 )
659+ if (std::distance (I, E) <= N )
658660 return 0 ;
659661 // Check that the line after the inner result starts with a closing brace
660662 // which we are permitted to merge into one line.
661- if (I[2 + MergedLines ]->First ->is (tok::r_brace) &&
662- !I[2 + MergedLines ]->First ->MustBreakBefore &&
663- !I[1 + MergedLines ]->Last ->is (TT_LineComment ) &&
664- nextNLinesFitInto (I, I + 2 + MergedLines + 1 , Limit)) {
665- return 2 + MergedLines ;
663+ if (I[N ]->First ->is (tok::r_brace) &&
664+ !I[N ]->First ->MustBreakBefore &&
665+ !I[MergedLines + 1 ]->Last ->is (tok::comment ) &&
666+ nextNLinesFitInto (I, I + N + 1 , Limit)) {
667+ return N ;
666668 }
667669 return 0 ;
668670 }
0 commit comments