[PATCH] D12231: Add use-auto check to modernize module.

Alexander Kornienko via cfe-commits cfe-commits at lists.llvm.org
Fri Aug 21 05:39:16 PDT 2015


alexfh added inline comments.

================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:45
@@ +44,3 @@
+
+  // The following test is based on DeclPrinter::VisitVarDecl() or find if an
+  // initializer is implicit or not.
----------------
I can't parse it with 'or'. Did you mean something different?

================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:77
@@ +76,3 @@
+  }
+  return false;
+}
----------------
This is a dead code now.

================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:293
@@ +292,3 @@
+  SourceRange Range(V->getTypeSourceInfo()->getTypeLoc().getSourceRange());
+  auto Diag = diag(Range.getBegin(), "use auto when declaring iterators")
+              << FixItHint::CreateReplacement(Range, "auto");
----------------
No need for a variable here. Just `diag(...) << ...;`

================
Comment at: clang-tidy/modernize/UseAutoCheck.cpp:343
@@ +342,3 @@
+      FirstDecl->getTypeSourceInfo()->getTypeLoc().getSourceRange());
+  auto Diag = diag(Range.getBegin(), "use auto when initializing with new");
+
----------------
I'd expand the message with an explanation _why_ `auto` is better here: "use auto when initializing with new to avoid duplicating the type name".

It might be useful to include the type name to the message, but we can leave this until we have specific examples of when it helps.


http://reviews.llvm.org/D12231





More information about the cfe-commits mailing list