This is an archive of the discontinued LLVM Phabricator instance.

[clang-tidy] Add non-constant references in function parameters check.
ClosedPublic

Authored by hokein on Jan 29 2016, 2:41 AM.

Diff Detail

Repository
rL LLVM

Event Timeline

hokein updated this revision to Diff 46368.Jan 29 2016, 2:41 AM
hokein retitled this revision from to [clang-tidy] Add non-constant references in function parameters check..
hokein updated this object.
hokein set the repository for this revision to rL LLVM.
hokein added a subscriber: cfe-commits.
hokein updated this revision to Diff 46510.Feb 1 2016, 1:02 AM

Fix code style.

alexfh edited edge metadata.Feb 1 2016, 7:05 AM

Thanks! A few comments.

clang-tidy/google/NonConstReferences.cpp
54 ↗(On Diff #46510)

This could be auto to avoid duplicating the type name.

81 ↗(On Diff #46510)

The return should be on the next line (clang-format -style=llvm should get this right).

105 ↗(On Diff #46510)

We can avoid calling (the more expensive) getNameAsString here:

if (Function->getDeclName().isIdentifier() && Function->getName() == "swap") ...
109 ↗(On Diff #46510)

I'd better avoid calling getAsString here as well, but I don't see an easy way to do this.

test/clang-tidy/google-runtime-references.cpp
1 ↗(On Diff #46510)

I think, this test can use the %check_clang_tidy script, since it doesn't seem to do anything the script doesn't support (you'll need to s/CHECK/CHECK-MESSAGES/ to make it work, though).

hokein updated this revision to Diff 46628.Feb 2 2016, 1:28 AM
hokein edited edge metadata.

Address comments.

hokein marked 4 inline comments as done.Feb 2 2016, 1:32 AM
alexfh accepted this revision.Feb 2 2016, 9:16 AM
alexfh edited edge metadata.

Looks good with one nit.

Thank you!

test/clang-tidy/google-runtime-references.cpp
1 ↗(On Diff #46628)

-std=c++11 is added by default. Please remove everything after the %t.

This revision is now accepted and ready to land.Feb 2 2016, 9:16 AM
This revision was automatically updated to reflect the committed changes.
// Don't warn on dependent types in templates.

Hmm, i wanted to try to fix my Bug 32683 about templated references being ignored, and i found out that it is actually intentional...
Reading https://google.github.io/styleguide/cppguide.html#Reference_Arguments i do not see why non-const T & should be ignored.
Is there a reason for this? Or perhaps, looking at the g9()/g10(), this implicit whitelisting should be more fine-grained, specific?