<div dir="ltr"><br><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Aug 15, 2016 at 5:20 PM, Kirill Bobyrev via cfe-commits <span dir="ltr"><<a href="mailto:cfe-commits@lists.llvm.org" target="_blank">cfe-commits@lists.llvm.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">Author: omtcyfz<br>
Date: Mon Aug 15 18:20:05 2016<br>
New Revision: 278760<br>
<br>
URL: <a href="http://llvm.org/viewvc/llvm-project?rev=278760&view=rev" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project?rev=278760&view=rev</a><br>
Log:<br>
[clang-rename] cleanup `auto` usages<br>
<br>
As Alexander pointed out, LLVM Coding Standards are more conservative about<br>
using auto, i.e. it should be used in the following situations:<br>
<br>
* When the type is obvious, i.e. explicitly mentioned in the same expression.<br>
For example `if (const clang::FieldDecl *FieldDecl = Initializer->getMember())`.<br>
* When the type is totally non-obvious and one iterates over something. For<br>
example<br>
`for (const auto &CurrDecl : Context.<wbr>getTranslationUnitDecl()-><wbr>decls())`.<br>
<br>
Otherwise the type should be explicitly stated.<br>
<br>
Reviewers: alexfh<br>
<br>
Differential Revision: <a href="https://reviews.llvm.org/D23397" rel="noreferrer" target="_blank">https://reviews.llvm.org/<wbr>D23397</a><br>
<br>
Modified:<br>
    clang-tools-extra/trunk/clang-<wbr>rename/RenamingAction.cpp<br>
    clang-tools-extra/trunk/clang-<wbr>rename/USRFinder.cpp<br>
    clang-tools-extra/trunk/clang-<wbr>rename/USRFindingAction.cpp<br>
    clang-tools-extra/trunk/clang-<wbr>rename/USRLocFinder.cpp<br>
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>rename/RenamingAction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/RenamingAction.cpp?rev=278760&r1=278759&r2=278760&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-rename/<wbr>RenamingAction.cpp?rev=278760&<wbr>r1=278759&r2=278760&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>rename/RenamingAction.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>rename/RenamingAction.cpp Mon Aug 15 18:20:05 2016<br>
@@ -52,7 +52,7 @@ public:<br>
   void HandleOneRename(ASTContext &Context, const std::string &NewName,<br>
                        const std::string &PrevName,<br>
                        const std::vector<std::string> &USRs) {<br>
-    const auto &SourceMgr = Context.getSourceManager();<br>
+    const SourceManager &SourceMgr = Context.getSourceManager();<br>
     std::vector<SourceLocation> RenamingCandidates;<br>
     std::vector<SourceLocation> NewCandidates;<br>
<br>
@@ -61,7 +61,7 @@ public:<br>
     RenamingCandidates.insert(<wbr>RenamingCandidates.end(), NewCandidates.begin(),<br>
                               NewCandidates.end());<br>
<br>
-    auto PrevNameLen = PrevName.length();<br>
+    unsigned PrevNameLen = PrevName.length();<br>
     for (const auto &Loc : RenamingCandidates) {<br>
       if (PrintLocations) {<br>
         FullSourceLoc FullLoc(Loc, SourceMgr);<br>
@@ -70,8 +70,8 @@ public:<br>
                << FullLoc.<wbr>getSpellingColumnNumber() << "\n";<br>
       }<br>
       // FIXME: better error handling.<br>
-      auto Replace = tooling::Replacement(<wbr>SourceMgr, Loc, PrevNameLen, NewName);<br>
-      auto Err = FileToReplaces[Replace.<wbr>getFilePath()].add(Replace);<br>
+      tooling::Replacement Replace(SourceMgr, Loc, PrevNameLen, NewName);<br>
+      llvm::Error Err = FileToReplaces[Replace.<wbr>getFilePath()].add(Replace);<br>
       if (Err)<br>
         llvm::errs() << "Renaming failed in " << Replace.getFilePath() << "! "<br>
                      << llvm::toString(std::move(Err)) << "\n";<br>
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>rename/USRFinder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRFinder.cpp?rev=278760&r1=278759&r2=278760&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-rename/USRFinder.<wbr>cpp?rev=278760&r1=278759&r2=<wbr>278760&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>rename/USRFinder.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>rename/USRFinder.cpp Mon Aug 15 18:20:05 2016<br>
@@ -60,13 +60,13 @@ public:<br>
   // Expression visitors:<br>
<br>
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {<br>
-    const auto *Decl = Expr->getFoundDecl();<br>
+    const NamedDecl *Decl = Expr->getFoundDecl();<br>
     return setResult(Decl, Expr->getLocation(),<br>
                      Decl->getNameAsString().<wbr>length());<br>
   }<br>
<br>
   bool VisitMemberExpr(const MemberExpr *Expr) {<br>
-    const auto *Decl = Expr->getFoundDecl().getDecl()<wbr>;<br>
+    const NamedDecl *Decl = Expr->getFoundDecl().getDecl()<wbr>;<br>
     return setResult(Decl, Expr->getMemberLoc(),<br>
                      Decl->getNameAsString().<wbr>length());<br>
   }<br>
@@ -74,9 +74,10 @@ public:<br>
   // Other visitors:<br>
<br>
   bool VisitTypeLoc(const TypeLoc Loc) {<br>
-    const auto TypeBeginLoc = Loc.getBeginLoc();<br>
-    const auto TypeEndLoc = Lexer::getLocForEndOfToken(<br>
-        TypeBeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());<br>
+    const SourceLocation TypeBeginLoc = Loc.getBeginLoc();<br>
+    const SourceLocation TypeEndLoc = Lexer::getLocForEndOfToken(<br>
+                             TypeBeginLoc, 0, Context.getSourceManager(),<br>
+                             Context.getLangOpts());<br>
     if (const auto *TemplateTypeParm =<br>
             dyn_cast<TemplateTypeParmType><wbr>(Loc.getType())) {<br>
       return setResult(TemplateTypeParm-><wbr>getDecl(), TypeBeginLoc, TypeEndLoc);<br>
@@ -117,7 +118,8 @@ public:<br>
   // \returns false on success and sets Result.<br>
   void handleNestedNameSpecifierLoc(<wbr>NestedNameSpecifierLoc NameLoc) {<br>
     while (NameLoc) {<br>
-      const auto *Decl = NameLoc.<wbr>getNestedNameSpecifier()-><wbr>getAsNamespace();<br>
+      const NamespaceDecl *Decl =<br>
+          NameLoc.<wbr>getNestedNameSpecifier()-><wbr>getAsNamespace();<br>
       setResult(Decl, NameLoc.getLocalBeginLoc(), NameLoc.getLocalEndLoc());<br>
       NameLoc = NameLoc.getPrefix();<br>
     }<br>
@@ -173,14 +175,13 @@ private:<br>
<br>
 const NamedDecl *getNamedDeclAt(const ASTContext &Context,<br>
                                 const SourceLocation Point) {<br>
-  const auto SearchFile = Context.getSourceManager().<wbr>getFilename(Point);<br>
+  StringRef SearchFile = Context.getSourceManager().<wbr>getFilename(Point);<br>
   NamedDeclFindingASTVisitor Visitor(Point, Context);<br>
<br>
   // We only want to search the decls that exist in the same file as the point.<br>
-  auto Decls = Context.<wbr>getTranslationUnitDecl()-><wbr>decls();<br>
-  for (auto &CurrDecl : Decls) {<br>
-    const auto FileLoc = CurrDecl->getLocStart();<br>
-    const auto FileName = Context.getSourceManager().<wbr>getFilename(FileLoc);<br>
+  for (const auto *CurrDecl : Context.<wbr>getTranslationUnitDecl()-><wbr>decls()) {<br>
+    const SourceLocation FileLoc = CurrDecl->getLocStart();<br>
+    StringRef FileName = Context.getSourceManager().<wbr>getFilename(FileLoc);<br>
     // FIXME: Add test.<br>
     if (FileName == SearchFile) {<br>
       Visitor.TraverseDecl(CurrDecl)<wbr>;<br></blockquote><div><br></div><div>Visitor.TraverseDecl doesn't have a const overload, so this change seems to have broken</div><div>the clang build.</div><div> </div><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex">
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>rename/USRFindingAction.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRFindingAction.cpp?rev=278760&r1=278759&r2=278760&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-rename/<wbr>USRFindingAction.cpp?rev=<wbr>278760&r1=278759&r2=278760&<wbr>view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>rename/USRFindingAction.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>rename/USRFindingAction.cpp Mon Aug 15 18:20:05 2016<br>
@@ -116,14 +116,14 @@ private:<br>
<br>
   void addUSRsOfOverridenFunctions(<wbr>const CXXMethodDecl *MethodDecl) {<br>
     USRSet.insert(getUSRForDecl(<wbr>MethodDecl));<br>
-    for (auto &OverriddenMethod : MethodDecl->overridden_<wbr>methods()) {<br>
+    for (const auto &OverriddenMethod : MethodDecl->overridden_<wbr>methods()) {<br>
       // Recursively visit each OverridenMethod.<br>
       addUSRsOfOverridenFunctions(<wbr>OverriddenMethod);<br>
     }<br>
   }<br>
<br>
   bool checkIfOverriddenFunctionAscen<wbr>ds(const CXXMethodDecl *MethodDecl) {<br>
-    for (auto &OverriddenMethod : MethodDecl->overridden_<wbr>methods()) {<br>
+    for (const auto &OverriddenMethod : MethodDecl->overridden_<wbr>methods()) {<br>
       if (USRSet.find(getUSRForDecl(<wbr>OverriddenMethod)) != USRSet.end()) {<br>
         return true;<br>
       }<br>
@@ -143,10 +143,11 @@ private:<br>
<br>
 struct NamedDeclFindingConsumer : public ASTConsumer {<br>
   void HandleTranslationUnit(<wbr>ASTContext &Context) override {<br>
-    const auto &SourceMgr = Context.getSourceManager();<br>
+    const SourceManager &SourceMgr = Context.getSourceManager();<br>
     // The file we look for the USR in will always be the main source file.<br>
-    const auto Point = SourceMgr.<wbr>getLocForStartOfFile(<wbr>SourceMgr.getMainFileID())<br>
-                           .getLocWithOffset(<wbr>SymbolOffset);<br>
+    const SourceLocation Point =<br>
+        SourceMgr.<wbr>getLocForStartOfFile(<wbr>SourceMgr.getMainFileID())<br>
+            .getLocWithOffset(<wbr>SymbolOffset);<br>
     if (!Point.isValid())<br>
       return;<br>
     const NamedDecl *FoundDecl = nullptr;<br>
<br>
Modified: clang-tools-extra/trunk/clang-<wbr>rename/USRLocFinder.cpp<br>
URL: <a href="http://llvm.org/viewvc/llvm-project/clang-tools-extra/trunk/clang-rename/USRLocFinder.cpp?rev=278760&r1=278759&r2=278760&view=diff" rel="noreferrer" target="_blank">http://llvm.org/viewvc/llvm-<wbr>project/clang-tools-extra/<wbr>trunk/clang-rename/<wbr>USRLocFinder.cpp?rev=278760&<wbr>r1=278759&r2=278760&view=diff</a><br>
==============================<wbr>==============================<wbr>==================<br>
--- clang-tools-extra/trunk/clang-<wbr>rename/USRLocFinder.cpp (original)<br>
+++ clang-tools-extra/trunk/clang-<wbr>rename/USRLocFinder.cpp Mon Aug 15 18:20:05 2016<br>
@@ -67,7 +67,7 @@ public:<br>
   // Expression visitors:<br>
<br>
   bool VisitDeclRefExpr(const DeclRefExpr *Expr) {<br>
-    const auto *Decl = Expr->getFoundDecl();<br>
+    const NamedDecl *Decl = Expr->getFoundDecl();<br>
<br>
     if (USRSet.find(getUSRForDecl(<wbr>Decl)) != USRSet.end()) {<br>
       const SourceManager &Manager = Decl->getASTContext().<wbr>getSourceManager();<br>
@@ -79,7 +79,7 @@ public:<br>
   }<br>
<br>
   bool VisitMemberExpr(const MemberExpr *Expr) {<br>
-    const auto *Decl = Expr->getFoundDecl().getDecl()<wbr>;<br>
+    const NamedDecl *Decl = Expr->getFoundDecl().getDecl()<wbr>;<br>
     if (USRSet.find(getUSRForDecl(<wbr>Decl)) != USRSet.end()) {<br>
       const SourceManager &Manager = Decl->getASTContext().<wbr>getSourceManager();<br>
       SourceLocation Location = Manager.getSpellingLoc(Expr-><wbr>getMemberLoc());<br>
@@ -116,7 +116,8 @@ public:<br>
   // Namespace traversal:<br>
   void handleNestedNameSpecifierLoc(<wbr>NestedNameSpecifierLoc NameLoc) {<br>
     while (NameLoc) {<br>
-      const auto *Decl = NameLoc.<wbr>getNestedNameSpecifier()-><wbr>getAsNamespace();<br>
+      const NamespaceDecl *Decl =<br>
+          NameLoc.<wbr>getNestedNameSpecifier()-><wbr>getAsNamespace();<br>
       if (Decl && USRSet.find(getUSRForDecl(<wbr>Decl)) != USRSet.end()) {<br>
         checkAndAddLocation(NameLoc.<wbr>getLocalBeginLoc());<br>
       }<br>
@@ -126,8 +127,8 @@ public:<br>
<br>
 private:<br>
   void checkAndAddLocation(<wbr>SourceLocation Loc) {<br>
-    const auto BeginLoc = Loc;<br>
-    const auto EndLoc = Lexer::getLocForEndOfToken(<br>
+    const SourceLocation BeginLoc = Loc;<br>
+    const SourceLocation EndLoc = Lexer::getLocForEndOfToken(<br>
         BeginLoc, 0, Context.getSourceManager(), Context.getLangOpts());<br>
     StringRef TokenName =<br>
         Lexer::getSourceText(<wbr>CharSourceRange::<wbr>getTokenRange(BeginLoc, EndLoc),<br>
<br>
<br>
______________________________<wbr>_________________<br>
cfe-commits mailing list<br>
<a href="mailto:cfe-commits@lists.llvm.org">cfe-commits@lists.llvm.org</a><br>
<a href="http://lists.llvm.org/cgi-bin/mailman/listinfo/cfe-commits" rel="noreferrer" target="_blank">http://lists.llvm.org/cgi-bin/<wbr>mailman/listinfo/cfe-commits</a><br>
</blockquote></div><br></div></div>