We have a dozen of C++ files with some lambdas that make clang-format crash. One example is this code: auto found = range::find_if(vsProducts, [&](auto * aProduct) { static const Version verVs2017; return true; }); If I add this code to another C++ file and try to format (on save), it will crash and create a dump file. (the example code was reduced, but still two lines) I've trimmed the config file to just these two lines to reproduce the problem: BasedOnStyle: Mozilla AlignConsecutiveDeclarations: 'true' Thanks
I can reproduce with trunk and 5.0 but not 4.0, so this is a regression. Daniel: is there someone besides yourself who like looking into clang-format bugs? :-)
*** Bug 34071 has been marked as a duplicate of this bug. ***
I have made an workaround for me - simply commented out this assert. And it looks quite normal. I don't know why. :)
Some *blame* history: 1) assert added in rev 248999 [clang-format] Add support of consecutive declarations alignment 2) rev 295586 the assert was still valid 3) rev 306282 the assert is NOT valid anymore This means only four revisions left, most likely rev *298574* by nikola: > Fix issues in clang-format's AlignConsecutive modes. Indeed, a quick check confirms that rev 5.0.0.300231 is also affected.
+Nikola
krasimir: Maybe you could take a look?
(In reply to Andrey Rusanov from comment #3) > I have made an workaround for me - simply commented out this assert. And it > looks quite normal. I don't know why. :) It seems to misformat the test case if I do that: $ cat | bin/clang-format -style="{BasedOnStyle: Mozilla,AlignConsecutiveDeclarations: 'true'}" auto found = range::find_if(vsProducts, [&](auto * aProduct) { static const Version verVs2017; return true; }); auto found = range::find_if(vsProducts, [&](auto* aProduct) { static const VersionverVs2017; return true; }); Note that it breaks the code by concatenating "Version" and "verVs2017" :-(
(In reply to Hans Wennborg from comment #7) > Note that it breaks the code by concatenating "Version" and "verVs2017" :-( Confirmed that both the assert and the concatenation started with r298574.
Hello, I've sent this patch for review if anyone wants to give it a try: https://reviews.llvm.org/D37137
Not sure exactly how to fix it, but here's a minimal example that asserts: echo "v f([]() {y x; x;});" | bin/clang-format -style="{AlignConsecutiveDeclarations: 'true'}" And, interestingly, the following doesn't assert, but as you can see, the formatting is a bit odd: echo "vvvvvvvvvvvv f([]() {y x; x;});" | bin/clang-format -style="{AlignConsecutiveDeclarations: 'true'}" vvvvvvvvvvvv f([]() { y x; x; });
Sorry, didn't see your post/patch before I commented, but I tested it with my test case and it works great...
The patch was committed in r311792. I'll let it bake a little bit and then merge.
Merged in r311800. Thanks for fixing!