Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bad code alignment with multiple parenthesis #4207

Open
pemessier opened this issue Jan 19, 2024 · 4 comments
Open

Bad code alignment with multiple parenthesis #4207

pemessier opened this issue Jan 19, 2024 · 4 comments

Comments

@pemessier
Copy link

Using Uncrustify-0.78.1_f, with the default configuration.

Consider the following code:

int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
    const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
                             m_euler.TransformationMatrixGet()( 1, 2 ),
                             m_euler.TransformationMatrixGet()( 2, 2 ) );

                             const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
                             m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );

    return 1;
}

The last 2 lines before the return is not well aligned. However:

int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
    const CTMatrix4d& transformationMatrix = m_euler.TransformationMatrixGet();
    const CTUnitDird  normal( transformationMatrix( 0, 2 ),
                              transformationMatrix( 1, 2 ),
                              transformationMatrix( 2, 2 ) );

    const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
    m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );

    return 1;
}

This works as expected. Uncrustify seems to get confused because of the ()( … ) syntax.

@JanFeld
Copy link

JanFeld commented Jan 23, 2024

I maybe have a similar issue related to this with multiple consecutive parentheses/calls.

I'm using cxxopts for command line option parsing.

The syntax for adding/defining options is like this:

int main(int argc, char** argv)
{
	// ...

	cxxopts::Options options{argv[0], "Description"};

	options.add_options()
		("a,optionA", "Option A Help Description")
		("b,optionB", "Option B Help Description")
		("c,optionC", "Option C Help Description")
		("d,optionD", "Option D Help Description");

	// ...
}

When using uncrustify it will be formatted like this even though i'd like to have it formatted like above:

int main(int argc, char** argv)
{
	// ...

	cxxopts::Options options{argv[0], "Description"};

	options.add_options()
	("a,optionA", "Option A Help Description")
	("b,optionB", "Option B Help Description")
	("c,optionC", "Option C Help Description")
	("d,optionD", "Option D Help Description");

	// ...
}

I didn't find any option for consecutive parentheses and their indentation.
Maybe this is related, if not i'm sorry.
It can be my configuration though, even if i don't know which one it could be.

Version: Uncrustify-0.78.1-82-e5d093335

Cheers,
Jan

@guy-maurel
Copy link
Contributor

Sorry, I cannot reproduce.
Using the cfg-file:

indent_columns   = 4
indent_with_tabs = 0

with the command:

uncrustify -v
uncrustify -c pemessier.cfg -f pemessier.cpp

I get:
Uncrustify_d-0.78.1-92-8f96659fe-dirty
and the output file has no change.

I run under Linux.
Why the difference?

@JanFeld
Copy link

JanFeld commented Feb 5, 2024

When running uncrustify with the snippet from @pemessier i get another different result:

int CPtCloudDataSWL::ASCIIReadNbPts(const size_t nbPtsToRead_)
{
	const CTUnitDird normal(m_euler.TransformationMatrixGet()(0, 2),
		m_euler.TransformationMatrixGet()(1, 2),
		m_euler.TransformationMatrixGet()(2, 2));


		const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_; // see this additional indentation

		m_ptNormals.insert(m_ptNormals.end(), nbPtsAdded, CTDirToF(normal)); // and this one ..

	return 1;
}

I'm using tabs only and with the parameters you mentioned like the following:

indent_columns   = 8
indent_with_tabs = 2

On Linux, version Uncrustify-0.78.1-82-e5d093335.

My configuration file:
uncrustify.txt

@pemessier
Copy link
Author

int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
m_euler.TransformationMatrixGet()( 1, 2 ),
m_euler.TransformationMatrixGet()( 2, 2 ) );

                         const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
                         m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );

return 1;

}

Sorry my initial example was bad. This is the expected (no change) output that can be used as input:

int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
    const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
                             m_euler.TransformationMatrixGet()( 1, 2 ),
                             m_euler.TransformationMatrixGet()( 2, 2 ) );

    const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
    m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );

    return 1;
}

The assignment lines are left-indented by 4 spaces.

On Windows, running uncrustify.exe -c - pemessier.cpp produces the incorrect result;

int CPtCloudDataSWL::ASCIIReadNbPts( const size_t nbPtsToRead_ )
{
	const CTUnitDird normal( m_euler.TransformationMatrixGet()( 0, 2 ),
	                         m_euler.TransformationMatrixGet()( 1, 2 ),
	                         m_euler.TransformationMatrixGet()( 2, 2 ) );

	                         const size_t nbPtsAdded = m_pts.size() - nbPtsToRead_;
	                         m_ptNormals.insert( m_ptNormals.end(), nbPtsAdded, CTDirToF( normal ) );

	return 1;
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants