This fixes https://llvm.org/bugs/show_bug.cgi?id=25329, as well as misalignments like the following:
int a, b = 2; int c = 3;
Differential D14325
[clang-format] Do not align assignments that aren't after the same number of commas. (Closes: 25329) berenm on Nov 4 2015, 2:18 AM. Authored by
Details
This fixes https://llvm.org/bugs/show_bug.cgi?id=25329, as well as misalignments like the following: int a, b = 2; int c = 3;
Diff Detail Event TimelineComment Actions [clang-format] Count the number of braces and parens on the line instead of remembering only one. Comment Actions I've also added a fix for the other issue reported on the same bug. I could split the two reviews if necessary.
Comment Actions I like it :-)
Comment Actions [clang-format] alignConsecutiveXXX: replace the buggy paren / braces counter with a better scope tracker. Comment Actions Updated the diff with a fix for the issue reported in http://lists.llvm.org/pipermail/cfe-dev/2015-November/046057.html Comment Actions Sorry for being so slow to respond. Feel free to ping me more frequently ;-).
Comment Actions Looks awesome :-)
Comment Actions Submitted as r254406. Note that I had to make the struct "Change" public. How did this compile on your end? Comment Actions I don't have any compilation error with GCC 5.2.1. I tried again with Clang 3.8 and indeed there is this error: tools/clang/lib/Format/WhitespaceManager.cpp:155:51: error: 'Change' is a private member of 'clang::format::WhitespaceManager' SmallVector<WhitespaceManager::Change, 16> &Changes) { ^ tools/clang/lib/Format/WhitespaceManager.h:87:10: note: declared private here struct Change { ^ This can easily be reproduced: http://goo.gl/CUk665 vs http://goo.gl/6KcBFT I don't know precisely which one is correct here, it looks like to be related to the access permission in the context of a template function instantiation. |
Hm. So many lokal variables. I think it might make sense to wrap these in a class/struct? That could be a first step to re-using code in alignConsecutiveDeclarations.
Also, a comment would help here. Specifically, a comment explaining why you count commas, braces and parentheses (not explaining that this variables count them ;-) )