Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

astyle formatting multiple line <<

I'm using astyle which is great for applying standard style to existing code. However I've noticed that when it comes across this:

ostringstream myStream;
myStream << 1
         << 2;

it reformats to this:

ostringstream myStream;
myStream << 1
<< 2;

Here's my options file: (version 1.23)

--indent=spaces
--brackets=break
--indent-switches
--indent-namespaces
--min-conditional-indent=4
--break-closing-brackets
--pad-paren-in
--unpad-paren
--convert-tabs

Is there any way to make it line up the "<<" on the next line?

Edit:

I also tried version 1.22 with the following file (test.cpp):

void main()
{
    ostringstream myStream;
    myStream << 1
             << 2;
}

with the following options (format.txt):

--indent=spaces
--brackets=break-closing
--indent-switches
--indent-namespaces
--min-conditional-indent=4
--pad=paren-in
--unpad=paren
--convert-tabs

and the following command line:

astyle --options=format.txt test.cpp

which produced this:

void main()
{
    ostringstream myStream;
    myStream << 1
    << 2;
}
like image 445
markh44 Avatar asked Aug 26 '09 09:08

markh44


1 Answers

Final Conclusion is it's a bug see bottom

I tried to replicate your problem and was unable to get the behavior you are talking about (OP question update negates this)

Edit: (deleted content to update)

Parameter names have changed between 1.22 and 1.23.

If neither solves your problem, try uploading more code as an example, or otherwise try to replicate your problem using only the code you pasted here. (Done by OP)

I've also found that the order of the options seems to have made a difference on occasion. For example:

astyle --indent=tab --style=ansi test.cpp

is not the same as:

astyle --style=ansi --indent=tab test.cpp

Specifying the "--style=ansi" second effectively negates the "--indent=tab".

I would not be surprised if this might be your issue.

...But after playing around with this for 20 min, I'm convinced it's an astyle bug.

Edit to include link to bug: bug Thanks Markh44

like image 180
Catskul Avatar answered Sep 28 '22 01:09

Catskul