Replaces Token based approach to identify EndLoc of Stmt with AST traversal.
This also improves handling of macros.
Fixes Bugs 22785, 25970 and 35754.
Differential D75813
[clang-tidy] fix readability-braces-around-statements Stmt type dependency AlexanderLanin on Mar 7 2020, 10:21 AM. Authored by
Details Replaces Token based approach to identify EndLoc of Stmt with AST traversal. Fixes Bugs 22785, 25970 and 35754.
Diff Detail Event TimelineComment Actions
Comment Actions Accidentally reverted test file renaming in last commit. Fixed now.
Comment Actions Can you add a test case when the else body ends with braces. In one of the bug reports that case was mentioned else X = {6};
Comment Actions *ping* I have an opinion on NullStmt, but I would rather see this merged ;-) Comment Actions *ping* Comment Actions I agree this needs fixing too, Added a few more reviewers to help move this along
Comment Actions Rebased and stored at https://github.com/llvm/llvm-project/compare/9d6d4b07a...AlexanderLanin:readability-braces-around-statements?expand=1 so I have a branch next time I need to rebase :-) Still looking for someone to approve and to commit this change. Comment Actions Hey Alex, first thanks for the bug fixing! Of course we are interested in improvements in clang-tidy, but i think noone is actually employed to help out here and the normal reviewers have many, many reviews parallel. Sometimes stuff just slips through :/ I try to pick up review an @njames93 seems not have time (i dont have info, and you can just jump in again!). Two thoughts are added inline. Did you check the new revision against a big code-base like llvm (with fixit on and compilation + testing afterwards)? How did it go, anything outstanding happened?
Comment Actions @JonasToth I fully realize that it's voluntary and I do not have a solution. I have the same problem in a different area. Not sure what shall become of some OSS projects when it takes that long to get a patch in. But that's a different discussion. The patch as shown here generates ~130k braces on llvm, you can see it at https://github.com/llvm/llvm-project/commit/16d3ec868cf00
It's not tested against other codebases, but it had a test suite even before this patch. I'll get back regarding that removed assert ASAP. I don't remember, so I'll add it again and see what happens. Comment Actions That diff is showing different behaviour to the test cases. In the test cases if (...) something(); Will get changed to if (...) { something(); } However in the diff it is inserting a new line before the closing brace if (...) { something(); } This somewhat seems to decrease readability. Comment Actions @JonasToth: Cannot add assert. EndLoc is indeed invalid in case BeginLoc is outside the macro and EndLoc would be inside the macro. I've added a comment explaining that. @njames93: Sorry I generated the diff for github upload incorrectly. Yaml newline format has changed between release 11 and 12. One has to provide the new clang-apply-replacements-binary to run-clang-tidy. Comment Actions LGTM
Comment Actions It's been a while and I almost don't remember what this is. But it was a good fix and there is one LGTM. |
Why is this assertion removed? In the following lines EndLoc is used for a line-number calculation. Shouldn't EndLoc be valid for that to be correct?