Quuxplusone / LLVMBugzillaTest

0 stars 0 forks source link

clang-tidy: check return style #22415

Open Quuxplusone opened 9 years ago

Quuxplusone commented 9 years ago
Bugzilla Link PR22416
Status NEW
Importance P enhancement
Reported by Eugene Zelenko (eugene.zelenko@gmail.com)
Reported on 2015-01-30 16:08:10 -0800
Last modified on 2016-01-18 11:01:39 -0800
Version unspecified
Hardware All All
CC adrian@adek.io, alexfh@google.com, djasper@google.com, klimek@google.com, legalize@xmission.com, llvm-bugs@lists.llvm.org
Fixed by commit(s)
Attachments
Blocks
Blocked by
See also

Hi!

I think will be good idea to have checks for style of returns in non-void functions as part of readability checkers.

Round brackets should be used only for expressions, not around variable/member.

Eugene.

Quuxplusone commented 9 years ago

Please provide a couple of examples of what specific patterns you want to address with an explanation of why this matters. If there are any style guides that have this rule, please add a pointer to them.

Quuxplusone commented 9 years ago

Hi, Alexander!

Even such trivial situations like:

return (true);

return (d_ClassMember);

Ideally it's great it will be replaced with:

return true;

return d_ClassMember;

Eugene.

Quuxplusone commented 9 years ago

It looks like a matter of readability only. Implementing this check is a good task for someone who wants to start contributing to clang-tidy ;)

Quuxplusone commented 9 years ago
(In reply to comment #1)
> Please provide a couple of examples of what specific patterns you want to
> address with an explanation of why this matters. If there are any style
> guides that have this rule, please add a pointer to them.

Google Style guide: http://google-
styleguide.googlecode.com/svn/trunk/cppguide.html#Return_Values
Quuxplusone commented 8 years ago

Direct link to specific section in google style guide:

https://google.github.io/styleguide/cppguide.html#Return_Values

Quuxplusone commented 8 years ago

FYI, since it came up in my review of redundant return statements, I started making a check for this. I think I just need to check if dyn_cast(Return->getRetValue()) is non-zero and then it means it is of the form:

return(expr);

and not

return expr;

However, I haven't verified this yet.

Quuxplusone commented 8 years ago
Ah, I hav a diff for that: http://reviews.llvm.org/D16286
I used a similar matcher there.