[PATCH] D158363: [clang-format] Fix segmentation fault when formatting nested namespaces
Owen Pan via Phabricator via cfe-commits
cfe-commits at lists.llvm.org
Wed Aug 23 02:49:14 PDT 2023
owenpan added inline comments.
================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:389
auto *ClosingLine = AnnotatedLines.begin() + ClosingLineIndex + 1;
auto OutdentBy = I[J]->Level - TheLine->Level;
for (auto *CompactedLine = I + J; CompactedLine <= ClosingLine;
----------------
See below.
================
Comment at: clang/lib/Format/UnwrappedLineFormatter.cpp:392-393
++CompactedLine) {
if (!(*CompactedLine)->InPPDirective)
- (*CompactedLine)->Level -= OutdentBy;
+ (*CompactedLine)->Level -= std::min(OutdentBy, (*CompactedLine)->Level);
}
----------------
Or similar.
================
Comment at: clang/unittests/Format/FormatTest.cpp:4230-4237
+ verifyNoCrash("namespace ns1 { namespace ns2 { namespace ns3 {\n"
+ "void func_in_ns() {\n"
+ " int res{0};\n"
+ "// block for debug mode\n"
+ "#ifndef NDEBUG\n"
+ "#endif\n"
+ "}\n"
----------------
It seems that we can reduce the test case.
Repository:
rG LLVM Github Monorepo
CHANGES SINCE LAST ACTION
https://reviews.llvm.org/D158363/new/
https://reviews.llvm.org/D158363
More information about the cfe-commits
mailing list