common: formatting: layout_optimizer.cc: Wrapped hanging_indentation calculation Wrapped the calculation of hanging_indentation in TokenPartitionsLayoutOptimizer::CalculateOptimalLayout's kWrap case to never let the value drop below zero as it later causes a check failure Signed-off-by: Jan Bylicki <jbylicki@antmicro.com>
diff --git a/common/formatting/layout_optimizer.cc b/common/formatting/layout_optimizer.cc index ee18ab7..39e599d 100644 --- a/common/formatting/layout_optimizer.cc +++ b/common/formatting/layout_optimizer.cc
@@ -570,10 +570,14 @@ } } } + // std::max(hanging_indentation, 0) serves to resolve a case where + // the subsequent nodes will try to be indented below zero following + // a less-indented token eg. a macro const int hanging_indentation = (node.Children().size() > 1) - ? (node.Children()[1].Value().IndentationSpaces() - - node.Value().IndentationSpaces()) + ? std::max(node.Children()[1].Value().IndentationSpaces() - + node.Value().IndentationSpaces(), + 0) : 0; return factory_.Wrap(layouts.begin(), layouts.end(), false,