uncrustify
uncrustify copied to clipboard
indent_cpp_lambda_body problem with namespace
Config:
# Uncrustify-0.75
indent_cpp_lambda_body = true
Input:
namespace
{
void f1()
{
const auto lambda =
[]()
{
return 1;
};
}
} // namespace
void f2()
{
const auto lambda =
[]()
{
return 1;
};
}
Output (no changes were expected)
namespace
{
void f1()
{
const auto lambda =
[]()
{
return 1;
};
}
} // namespace
void f2()
{
const auto lambda =
[]()
{
return 1;
};
}
As you can see, the body of the lambda is being wrongly indented in f1(), just because it is enclosed in a namespace. This regression appeared in version 0.75.
using git bisect, I get 5052695a7a9289123539bd397966e97678f4dede is the problem. @JodiTheTigger Could you have a look and propose a new PR ? Thanks
Oh my, I'll have a look then
Yea, seems the code for dealing with these different lambda types is all broken now, due to the nature of where []()
is put for creating lambdas
void f1()
{
// New line you indent one stop for [](), as per normal rules for indenting a = on a new line
const auto lambda =
[]()
{
return 1;
};
}
vs this lambda
void f1()
{
// but here, treat it as a new scope, and do the braces accordingly
const auto lambda = []() -> int
{
return 1;
};
}
Still investigating a fix that doesn't cause any more regressions while formatting above as expected.
I would be fine.
Ok, figured it all out. Combo of misunderstanding some defaults (indent_align_assign=true
, indent_continue = 4
) and my original namespace indent code causing a ton of problems.
working on a pull request now, that seems to fix it all and pass tests.