This is an archive of the discontinued LLVM Phabricator instance.

[Clang] Fix Clang-tidy modernize-use-auto warnings in headers and generated files; other minor cleanups.
AbandonedPublic

Authored by Eugene.Zelenko on Oct 14 2015, 5:31 PM.

Details

Summary

I checked this patch on my own build on RHEL 6. Regressions were OK.

Diff Detail

Event Timeline

Eugene.Zelenko retitled this revision from to [Clang] Fix Clang-tidy modernize-use-auto warnings in headers and generated files; other minor cleanups..
Eugene.Zelenko updated this object.
Eugene.Zelenko added a reviewer: hans.
Eugene.Zelenko set the repository for this revision to rL LLVM.
Eugene.Zelenko added a subscriber: cfe-commits.
Eugene.Zelenko updated this object.
Eugene.Zelenko added a reviewer: aaron.ballman.

Synchronize with current code.

hans edited edge metadata.Nov 10 2015, 12:48 AM

Some of these are great improvements, especially using auto for iterators etc.

But I'm not sure we'll want to start changing "Foo *foo = new Foo;" to use auto everywhere. I expect we'd have to do that in a huge number of places?

include/clang/AST/ASTVector.h
385

I'm not sure this one is an improvement.

include/clang/AST/DeclContextInternals.h
90

Same here.

include/clang/AST/DeclTemplate.h
1726

But here it does make it nicer :-)

aaron.ballman added inline comments.Nov 10 2015, 5:21 AM
include/clang/Analysis/Analyses/Consumed.h
266

I don't know whether this is an improvement or not.

include/clang/Rewrite/Core/Rewriter.h
171

Not that this matters in the cases in this code, but const iterator is not the same as const_iterator. I think these changes are a step forward in terms of readability, but a step backwards in terms of the type system.

tools/libclang/Indexing.cpp
672

The extra parens do not add any value here.

utils/TableGen/ClangAttrEmitter.cpp
959

I really like all of these changes to this file!

include/clang/AST/ASTVector.h
385

At least handling of new will be consistent. This will also silent Clang-tidy warning.

include/clang/Analysis/Analyses/Consumed.h
266

This was changed for consistency with other code. I also think that it's good idea to place one statement per line.

include/clang/Rewrite/Core/Rewriter.h
171

I'm still learning C++11, so advices how to handle such situations properly are welcome!

tools/libclang/Indexing.cpp
672

Will remove them.

aaron.ballman added inline comments.Nov 11 2015, 7:51 AM
include/clang/AST/ASTVector.h
385

I'm not too concerned about the clang-tidy warning. It suggests that perhaps this checker could use an option to control this behavior, however.

I agree with Hans that a lot of the treatments of new expressions don't really seem to be improvements.

include/clang/AST/DeclTemplate.h
1726

I wonder if the heuristic is: when the new expression spans multiple lines, only replace the declaration type with auto if it causes the new expression to become a single-line expression.

include/clang/Analysis/Analyses/Consumed.h
266

This pattern is used in many places in the code base, it reduces vertical clutter, and it could be argued that it is easier to read because you don't have to interpret the namespace hierarchy.

include/clang/Rewrite/Core/Rewriter.h
171

In this case, I suppose it doesn't matter at all -- RewriteBuffers is a member variable being accessed from a const method, and so it will return a const_iterator. So technically, you don't even need the const here, just auto I.

The issue is more with code like:

struct S {
  SomeContainer C;

  void f() {
    SomeContainer::const_iterator I = C.begin();
  }
};

Replacing with auto here will deduce SomeContainer::iterator. The only way around that is with ugly casting, at which point I think leaving the declaration alone is the better choice.

For this code, I would remove the const and just leave it as auto I.

Eugene.Zelenko abandoned this revision.Nov 20 2015, 5:18 PM