This patch fixes issues with AlignConsecutiveAssignments and
AlignConsecutiveDeclarations such as this:
Before: int fun1(int a); double fun2(int b); typedef pair<key_type, T> type1; typedef pair<X, Y> type2; After: int fun1(int a); double fun2(int b); typedef pair<key_type, T> type1; typedef pair<X, Y> type2; and... Before: void fun(int x = 1) { int y = 2; } After: void fun(int x = 1) { int y = 2; }
The old alignment function was incapable of maintaining alignment whenever
the scope changed. To illustrate - in the first example mentioned, the
alignment of fun1 is lost by entering the nested scope of (int a).
This would cause the alignment to give up, and cause fun2 to start from a
blank slate. It would also cause false alignment, which is illustrated in
the second example above.
My primary motivator for this change is to have a list of function prototypes
line up.
This modification changes the alignment function so that it calls itself
recursively, at each change in scope depth. This allows it to maintain state
across different scope depths. A performance test against the current master
branch reveals a small (2.7%) speedup.
There are some new test cases which stress this functionality. In addition,
there were two historical test cases marked as "FIX ME", which now work as
intended.
In order to sense check, I have run this new implementation against the Clang
source code, with AlignConsecutiveAssignments:true and
AlignConsecutiveDeclarations:true. I then compared the old output with those
settings, vs the new output, with the same settings. All the changes that I
observed are explainable by the new logic, and IMO the formatted code looks
better with the new method.
This comment seems outdated.