This is an archive of the discontinued LLVM Phabricator instance.

[clang-rename] cleanup `auto` usages
ClosedPublic

Authored by omtcyfz on Aug 11 2016, 3:09 AM.

Details

Summary

As Alexander pointed out, LLVM Coding Standards are more conservative about using auto, i.e. it should be used in the following situations:

  • When the type is obvious, i.e. explicitly mentioned in the same expression. For example if (const clang::FieldDecl *FieldDecl = Initializer->getMember()).
  • When the type is totally non-obvious and one iterates over something. For example for (const auto &CurrDecl : Context.getTranslationUnitDecl()->decls()).

Otherwise the type should be explicitly stated.

Diff Detail

Repository
rL LLVM

Event Timeline

omtcyfz updated this revision to Diff 67666.Aug 11 2016, 3:09 AM
omtcyfz retitled this revision from to [clang-rename] cleanup `auto` usages.
omtcyfz updated this object.
omtcyfz added reviewers: alexfh, klimek.
omtcyfz added a subscriber: cfe-commits.
omtcyfz updated this object.Aug 11 2016, 5:06 AM
alexfh edited edge metadata.Aug 11 2016, 5:07 PM

A couple of comments inline.

clang-rename/RenamingAction.cpp
73 ↗(On Diff #67666)

Just remove the = tooling::Replacement part.

clang-rename/USRFinder.cpp
78 ↗(On Diff #67666)

Look, when you join these two declarations, the code becomes slightly less clear, slightly worse formatted and takes a bit more screen space. And I don't think any aspects of the code improve with this change. Seems like a net loss?

clang-rename/USRLocFinder.cpp
130 ↗(On Diff #67666)

Same problem with multiple values per declaration here.

alexfh requested changes to this revision.Aug 12 2016, 9:39 AM
alexfh edited edge metadata.
This revision now requires changes to proceed.Aug 12 2016, 9:39 AM
omtcyfz updated this revision to Diff 67989.Aug 14 2016, 2:45 PM
omtcyfz edited edge metadata.
omtcyfz marked 3 inline comments as done.

Address comments.

alexfh accepted this revision.Aug 15 2016, 4:17 PM
alexfh edited edge metadata.

LG with a couple of nits.

clang-rename/USRFinder.cpp
182 ↗(On Diff #67989)

Should this be const auto * instead?

clang-rename/USRLocFinder.cpp
132 ↗(On Diff #67989)

I suspect, clang-format will join the arguments to one line. Can you try? (maybe just git clang-format)

This revision is now accepted and ready to land.Aug 15 2016, 4:17 PM
omtcyfz updated this revision to Diff 68104.Aug 15 2016, 4:21 PM
omtcyfz edited edge metadata.

Address comments.

omtcyfz marked 2 inline comments as done.Aug 15 2016, 4:21 PM
omtcyfz added inline comments.
clang-rename/USRFinder.cpp
182–184 ↗(On Diff #68104)

Aww, sure. Thanks!

This revision was automatically updated to reflect the committed changes.
omtcyfz marked an inline comment as done.