This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] misc-macro-parentheses: Don't insert parentheses in variable declarations. Fixes bugzilla 26273
ClosedPublic

Authored by danielmarjamaki on Jun 1 2016, 2:54 AM.

Details

Summary

This is a quick fix for bugzilla 26273. parentheses should not be inserted in variable declarations.

This patch will introduce false negatives when a macro looks like it could be variable declaration but is not.

For example:

#define ABC   A*B*C

To avoid false positives in such expression, I am guessing that non-keywords such as "A", "B" and "C" are types or qualifiers so "A*B*C" is some variable declaration. My primary focus was to avoid FP.

Maybe there is a method that I am not aware of, to see if there is a type "A" during preprocessing.. that would be great.

The "possibleVarDecl" could be much more clever. For instance, variable declarations can at least contain :: < & also, I could handle those better also but that would mean more false negatives.

Diff Detail

Repository
rL LLVM

Event Timeline

danielmarjamaki retitled this revision from to [clang-tidy] misc-macro-parentheses: Don't insert parentheses in variable declarations. Fixes bugzilla 26273.
danielmarjamaki updated this object.
danielmarjamaki set the repository for this revision to rL LLVM.
danielmarjamaki added subscribers: cfe-commits, alexfh.

The "possibleVarDecl" could be much more clever. For instance, variable declarations can at least contain :: < & also, I could handle those better also but that would mean more false negatives.

I now saw bugzilla 27399 also.

I do need to handle templates also.

so I will send a new patch with updated possibleVarDecl().

danielmarjamaki removed rL LLVM as the repository for this revision.

Updated diff. Now also handles bugzilla 27399.

Eugene.Zelenko set the repository for this revision to rL LLVM.
Eugene.Zelenko removed a subscriber: alexfh.
etienneb edited reviewers, added: etienneb; removed: etienne.bergeron.Jun 1 2016, 12:56 PM
alexfh accepted this revision.Jun 3 2016, 2:43 PM
alexfh edited edge metadata.

Looks good with a few style comments.

clang-tidy/misc/MacroParenthesesCheck.cpp
82 ↗(On Diff #59208)

Either If we see int/short/struct/etc., or If we see int, short, struct, etc., .
Please also add a trailing period.

86 ↗(On Diff #59208)

Trailing period, please.

93 ↗(On Diff #59208)

Please remove parentheses around the method call.

97 ↗(On Diff #59208)

Trailing period.

105 ↗(On Diff #59208)

Trailing period.

158 ↗(On Diff #59208)

ditto

This revision is now accepted and ready to land.Jun 3 2016, 2:43 PM
Closed by commit rL272128 (authored by danielmarjamaki). · Explain WhyJun 8 2016, 3:37 AM
This revision was automatically updated to reflect the committed changes.