llvm / llvm-project

The LLVM Project is a collection of modular and reusable compiler and toolchain technologies.
http://llvm.org
Other
28.71k stars 11.87k forks source link

clang-tidy: check return style #22790

Open EugeneZelenko opened 9 years ago

EugeneZelenko commented 9 years ago
Bugzilla Link 22416
Version unspecified
OS All
CC @LegalizeAdulthood

Extended Description

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.

llvmbot commented 8 years ago

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

LegalizeAdulthood 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.

LegalizeAdulthood commented 8 years ago

Direct link to specific section in google style guide:

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

EugeneZelenko 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.

Google Style guide: http://google-styleguide.googlecode.com/svn/trunk/cppguide.html#Return_Values

llvmbot 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 ;)

EugeneZelenko 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.

llvmbot 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.