clang-rename: improve error message when -old-name is used and could not find symbol
authorMiklos Vajna <vmiklos@vmiklos.hu>
Tue, 30 Aug 2016 07:23:24 +0000 (07:23 +0000)
committerMiklos Vajna <vmiklos@vmiklos.hu>
Tue, 30 Aug 2016 07:23:24 +0000 (07:23 +0000)
Old output was:

clang-rename: could not find symbol at tools/clang/tools/extra/test/clang-rename/ClassFindByName.cpp:1:1 (offset 0).

Reviewers: omtcyfz

Differential Revision: https://reviews.llvm.org/D24002

llvm-svn: 280062

clang-tools-extra/clang-rename/USRFindingAction.cpp
clang-tools-extra/test/clang-rename/InvalidOldName.cpp [new file with mode: 0644]

index 469d365..c92e031 100644 (file)
@@ -157,12 +157,15 @@ struct NamedDeclFindingConsumer : public ASTConsumer {
       FoundDecl = getNamedDeclFor(Context, OldName);
     }
     if (FoundDecl == nullptr) {
-      FullSourceLoc FullLoc(Point, SourceMgr);
-      errs() << "clang-rename: could not find symbol at "
-             << SourceMgr.getFilename(Point) << ":"
-             << FullLoc.getSpellingLineNumber() << ":"
-             << FullLoc.getSpellingColumnNumber() << " (offset " << SymbolOffset
-             << ").\n";
+      if (OldName.empty()) {
+        FullSourceLoc FullLoc(Point, SourceMgr);
+        errs() << "clang-rename: could not find symbol at "
+               << SourceMgr.getFilename(Point) << ":"
+               << FullLoc.getSpellingLineNumber() << ":"
+               << FullLoc.getSpellingColumnNumber() << " (offset "
+               << SymbolOffset << ").\n";
+      } else
+        errs() << "clang-rename: could not find symbol " << OldName << ".\n";
       return;
     }
 
diff --git a/clang-tools-extra/test/clang-rename/InvalidOldName.cpp b/clang-tools-extra/test/clang-rename/InvalidOldName.cpp
new file mode 100644 (file)
index 0000000..11f2763
--- /dev/null
@@ -0,0 +1,2 @@
+// RUN: not clang-rename rename-all -new-name=Foo -old-name=Bar %s -- 2>&1 | FileCheck %s
+// CHECK: clang-rename: could not find symbol Bar.