uncrustify icon indicating copy to clipboard operation
uncrustify copied to clipboard

indent_cpp_lambda_body problem with namespace

Open chris-mich opened this issue 2 years ago • 4 comments

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.

chris-mich avatar May 16 '22 16:05 chris-mich

using git bisect, I get 5052695a7a9289123539bd397966e97678f4dede is the problem. @JodiTheTigger Could you have a look and propose a new PR ? Thanks

gmaurel avatar May 20 '22 08:05 gmaurel

Oh my, I'll have a look then

JodiTheTigger avatar May 24 '22 08:05 JodiTheTigger

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.

JodiTheTigger avatar Jun 23 '22 03:06 JodiTheTigger

I would be fine.

gmaurel avatar Jul 03 '22 16:07 gmaurel

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.

JodiTheTigger avatar Aug 26 '22 04:08 JodiTheTigger