[clang-rename] check whether -new-name is valid identifier in C++17
authorKirill Bobyrev <omtcyfz@gmail.com>
Thu, 21 Jul 2016 10:21:31 +0000 (10:21 +0000)
committerKirill Bobyrev <omtcyfz@gmail.com>
Thu, 21 Jul 2016 10:21:31 +0000 (10:21 +0000)
llvm-svn: 276259

clang-tools-extra/clang-rename/tool/ClangRename.cpp
clang-tools-extra/test/clang-rename/InvalidNewName.cpp [new file with mode: 0644]
clang-tools-extra/test/clang-rename/NoNewName.cpp

index 7475211..23d3126 100644 (file)
@@ -99,7 +99,18 @@ int main(int argc, const char **argv) {
   // Check the arguments for correctness.
 
   if (NewName.empty()) {
-    errs() << "clang-rename: no new name provided.\n\n";
+    errs() << "ERROR: no new name provided.\n\n";
+    exit(1);
+  }
+
+  // Check if NewName is a valid identifier in C++17.
+  LangOptions Options;
+  Options.CPlusPlus = true;
+  Options.CPlusPlus1z = true;
+  IdentifierTable Table(Options);
+  auto NewNameTokKind = Table.get(NewName).getTokenID();
+  if (!tok::isAnyIdentifier(NewNameTokKind)) {
+    errs() << "ERROR: new name is not a valid identifier in  C++17.\n\n";
     exit(1);
   }
 
diff --git a/clang-tools-extra/test/clang-rename/InvalidNewName.cpp b/clang-tools-extra/test/clang-rename/InvalidNewName.cpp
new file mode 100644 (file)
index 0000000..826771a
--- /dev/null
@@ -0,0 +1,2 @@
+// RUN: not clang-rename -new-name=class -offset=133 %s 2>&1 | FileCheck %s
+// CHECK: ERROR: new name is not a valid identifier in  C++17.
index d50efd6..445f94a 100644 (file)
@@ -1,4 +1,4 @@
 // Check for an error while -new-name argument has not been passed to
 // clang-rename.
 // RUN: not clang-rename -offset=133 %s 2>&1 | FileCheck %s
-// CHECK: clang-rename: no new name provided.
+// CHECK: ERROR: no new name provided.