curdeius updated this revision to Diff 442482. curdeius marked an inline comment as done. curdeius added a comment.
Address comments. Repository: rG LLVM Github Monorepo CHANGES SINCE LAST ACTION https://reviews.llvm.org/D129064/new/ https://reviews.llvm.org/D129064 Files: clang/lib/Format/UnwrappedLineFormatter.cpp clang/unittests/Format/FormatTestSelective.cpp Index: clang/unittests/Format/FormatTestSelective.cpp =================================================================== --- clang/unittests/Format/FormatTestSelective.cpp +++ clang/unittests/Format/FormatTestSelective.cpp @@ -609,6 +609,14 @@ " return a == 8 ? 32 : 16;\n" "}\n"; EXPECT_EQ(Code, format(Code, 40, 0)); + + // https://llvm.org/PR56352 + Style.CompactNamespaces = true; + Style.NamespaceIndentation = FormatStyle::NI_All; + Code = "\n" + "namespace ns1 { namespace ns2 {\n" + "}}"; + EXPECT_EQ(Code, format(Code, 0, 0)); } } // end namespace Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -66,7 +66,6 @@ (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth; Indent = Line.Level * IndentWidth + AdditionalIndent; } else { - IndentForLevel.resize(Line.Level + 1); Indent = getIndent(Line.Level); } if (static_cast<int>(Indent) + Offset >= 0) @@ -91,6 +90,7 @@ unsigned LevelIndent = Line.First->OriginalColumn; if (static_cast<int>(LevelIndent) - Offset >= 0) LevelIndent -= Offset; + assert(Line.Level < IndentForLevel.size()); if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) && !Line.InPPDirective) { IndentForLevel[Line.Level] = LevelIndent;
Index: clang/unittests/Format/FormatTestSelective.cpp =================================================================== --- clang/unittests/Format/FormatTestSelective.cpp +++ clang/unittests/Format/FormatTestSelective.cpp @@ -609,6 +609,14 @@ " return a == 8 ? 32 : 16;\n" "}\n"; EXPECT_EQ(Code, format(Code, 40, 0)); + + // https://llvm.org/PR56352 + Style.CompactNamespaces = true; + Style.NamespaceIndentation = FormatStyle::NI_All; + Code = "\n" + "namespace ns1 { namespace ns2 {\n" + "}}"; + EXPECT_EQ(Code, format(Code, 0, 0)); } } // end namespace Index: clang/lib/Format/UnwrappedLineFormatter.cpp =================================================================== --- clang/lib/Format/UnwrappedLineFormatter.cpp +++ clang/lib/Format/UnwrappedLineFormatter.cpp @@ -66,7 +66,6 @@ (Style.PPIndentWidth >= 0) ? Style.PPIndentWidth : Style.IndentWidth; Indent = Line.Level * IndentWidth + AdditionalIndent; } else { - IndentForLevel.resize(Line.Level + 1); Indent = getIndent(Line.Level); } if (static_cast<int>(Indent) + Offset >= 0) @@ -91,6 +90,7 @@ unsigned LevelIndent = Line.First->OriginalColumn; if (static_cast<int>(LevelIndent) - Offset >= 0) LevelIndent -= Offset; + assert(Line.Level < IndentForLevel.size()); if ((!Line.First->is(tok::comment) || IndentForLevel[Line.Level] == -1) && !Line.InPPDirective) { IndentForLevel[Line.Level] = LevelIndent;
_______________________________________________ cfe-commits mailing list cfe-commits@lists.llvm.org https://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits