C++11 brace initialization messes up with a condition which is used to check whether we are past the end of the statement intended to be enclosed with braces. Fix looks one token ahead, to check whether we are in a situation of "};" which could suggest a brace initialization is used and shoud work fine in other cases.
Details
Diff Detail
Event Timeline
clang-tidy/readability/BracesAroundStatementsCheck.cpp | ||
---|---|---|
63–72 | This might not be the best approach. Maybe it will be better to try to find the matching opening brace and see whether it is the opening brace for 'then' block. Feel free to throw more suggestions. |
clang-tidy/readability/BracesAroundStatementsCheck.cpp | ||
---|---|---|
63–72 | Maybe just skip correct bracket sequences (a statement can also contain lambdas, subscript expressions and normal parentheses in various combinations)? |
clang-tidy/readability/BracesAroundStatementsCheck.cpp | ||
---|---|---|
63–72 | Well, we could just remove TokKind == tok::r_brace in line 64. I don't really understand why this check is there. The test suite passes if I remove that check, including the new cases I have added. Maybe that's the way to go? I tracked the initial commit which introduced TokKind == tok::r_brace: D5395 and I don't see a clear reason why it needs to be there. Do you know why we need it? |
clang-tidy/readability/BracesAroundStatementsCheck.cpp | ||
---|---|---|
63–72 |
You mean line 74, I guess. It should be easy to check if removing it helps by running tests and applying fixes to a large enough codebase, e.g. LLVM+Clang, and running its tests to ensure the correctness of changes + manual inspection of a few replacements. |
Here is the r_brace use case:
if (true) while ("ok") {}
Unfortunately it looks quite similar to:
if (true) s = {};
This might not be the best approach. Maybe it will be better to try to find the matching opening brace and see whether it is the opening brace for 'then' block. Feel free to throw more suggestions.