Details
Diff Detail
Event Timeline
Here is a potential failure scenario
(test.cpp)
void *bar(); void foo() { void *p; int i = 0; while ((p = bar())) { i++; } }
(.clang-format)
Language: Cpp RemoveParentheses: ReturnStatement
clang-format test.cpp > test2.cpp
(test2.cpp)
void *bar(); void foo() { void *p; int i = 0; while (p = bar()) { i++; } }
clang test2.cpp
test2.cpp:7:12: warning: using the result of an assignment as a condition without parentheses [-Wparentheses] while (p = bar()) { ~~^~~~~~~ test2.cpp:7:12: note: place parentheses around the assignment to silence this warning while (p = bar()) { ^ ( ) test2.cpp:7:12: note: use '==' to turn this assignment into an equality comparison while (p = bar()) { ^ == 1 warning generated.
Yep! After reformating clang/lib/Format/ and rebuilding clang-format, I got the same warning:
WhitespaceManager.cpp:233:45: warning: using the result of an assignment as a condition without parentheses [-Wparentheses] } else if (Change.StartOfBlockComment = LastBlockComment) { ~~~~~~~~~~~~~~~~~~~~~~~~~~~^~~~~~~~~~~~~~~~~~ /Users/Owen/llvm-project/clang/lib/Format/WhitespaceManager.cpp:233:45: note: place parentheses around the assignment to silence this warning } else if (Change.StartOfBlockComment = LastBlockComment) { ^ ( ) /Users/Owen/llvm-project/clang/lib/Format/WhitespaceManager.cpp:233:45: note: use '==' to turn this assignment into an equality comparison } else if (Change.StartOfBlockComment = LastBlockComment) { ^ == 1 warning generated.
I reckon you could detect the = condition between the matching paren don't you? I ran this on my quite large code base and this was one of the only issues I've seen thus far..
This is a great feature, for my codebase this generated changes in about 10% of all files (but often only a couple of lines or so per file, mostly people doing return (*this);
I think this will be a great feature to have.
clang/unittests/Format/FormatTest.cpp | ||
---|---|---|
25808 | Should check for __attribute((what ever))__. |
Don't remove the outermost double parentheses after if/while if there is an = inside. Also rename the options.
Absolutely.
clang/docs/ClangFormatStyleOptions.rst | ||
---|---|---|
4363 | Renamed it to MultipleParentheses, which means to remove redundant parentheses found in multiple (double, triple, etc.) parens. (The comment on line 3372 in Format.h says Types of redundant parentheses to remove, but it's changed to Possible values by dump_format_style.py in the documentation.) This is IMO more consistent with ReturnStatement below, but I'm open to other suggestions. | |
clang/unittests/Format/FormatTest.cpp | ||
25808 | What's special about this? It's agnostic about this option as it should be. |
clang/unittests/Format/FormatTest.cpp | ||
---|---|---|
25808 | I did not see, that you already had an example with __attribute__. |
Did you forget about GNU statement expressions?
if (({ foo(); bar(); })) { }
clang/docs/ReleaseNotes.rst | ||
---|---|---|
804 | The option is misspelled. |
Should this be Leave, meaning "Don't touch anything?" vs None which could be confused with "No Parentheses"