This is an archive of the discontinued LLVM Phabricator instance.

Remove dangling parenthesis.
ClosedPublic

Authored by angelgarcia on Sep 24 2015, 6:37 AM.

Diff Detail

Event Timeline

angelgarcia retitled this revision from to Remove dangling parenthesis..
angelgarcia updated this object.
angelgarcia added a reviewer: alexfh.
angelgarcia added subscribers: klimek, cfe-commits.

Can you add a test where we need the parens? (where the element is of ** type or something)

Added a test where the parenthesis must not be removed, and one where they should.

klimek added inline comments.Sep 24 2015, 7:39 AM
clang-tidy/modernize/LoopConvertCheck.cpp
482

Perhaps add a comment (or correct me if I'm wrong ;)
Usage.Expression contains the DeclRefExpr from the point of usage.
Parens around a simple DeclRefExpr can always be removed.

(can Usage.Expression be something more complex?)

alexfh edited reviewers, added: klimek; removed: alexfh.Sep 24 2015, 7:41 AM

Usage.Expression can be:
-CXXMemberCallExpr: "container.at(i)"
-CXXOperatorCallExpr: "*it" or "container[i]"
-ArraySubscripExpr: "Arr[i]"
-UnaryOperator: "*ptr"
-MemberExpr: "it->member" (we only replace "it->" with "elem." in this
case).

The point is that all of them except the last one will be replaced by
"elem" (or any other identifier), so it will be a DeclRefExpr after the
change, and the parenthesis can always be removed. I can add a comment
explaining this.

Add comment.

klimek accepted this revision.Sep 24 2015, 8:11 AM
klimek edited edge metadata.

LG

This revision is now accepted and ready to land.Sep 24 2015, 8:11 AM
angelgarcia closed this revision.Sep 24 2015, 8:31 AM